![[プレビュー] Azure Functions をリモート MCP サーバーとして使えるようになったので試してみた](https://images.ctfassets.net/ct0aopd36mqt/4AJd3M26yescaNaY21CYmQ/9730e95c53a7b3049c6da6d4c0b1dec9/mcp.png)
[プレビュー] Azure Functions をリモート MCP サーバーとして使えるようになったので試してみた
いわさです。
最近話題な MCP ですが、先日 Microsoft Azure の Azure Functions をリモート MCP サーバーとしてデプロイできるアップデートがプレビューでリリースされました。
こちら、.NET / Python / TypeScript の 3 つのクイックスタートテンプレートが用意されており、数ステップですぐに試すことが出来ます。
.NET で試してみた
今回はこの中から .NET を使ったデプロイしてみます。
右も左もわからない状態なので、以下に従って進めてみたいと思います。
まず、ローカル上で関数の動作確認をし、その後クラウド上へデプロイする手順が紹介されています。
ローカルでの実行
サンプルの関数が Azure Storage を使うため、ローカル開発用に「Azurite」を使います。Azurite はオープンソースの Azure Blob、Queue Storage、Table Storage のエミュレーターです。Azure Storage を扱うアプリケーションのローカル開発に使うことが出来ます。[1]
% docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 \
mcr.microsoft.com/azure-storage/azurite
Unable to find image 'mcr.microsoft.com/azure-storage/azurite:latest' locally
latest: Pulling from azure-storage/azurite
6e771e15690e: Already exists
:
Azurite Blob service is starting at http://0.0.0.0:10000
Azurite Blob service is successfully listening at http://0.0.0.0:10000
Azurite Queue service is starting at http://0.0.0.0:10001
Azurite Queue service is successfully listening at http://0.0.0.0:10001
Azurite Table service is starting at http://0.0.0.0:10002
Azurite Table service is successfully listening at http://0.0.0.0:10002
また、手順では Azure Functions Core Tools を使ってローカルで関数を実行しています。[2]
brew tap azure/functions
brew install azure-functions-core-tools@4
# if upgrading on a machine that has 2.x or 3.x installed:
brew link --overwrite azure-functions-core-tools@4
準備が出来たので、サンプルリポジトリからコードをクローンし、関数をローカル実行してみましょう。
% func start
Determining projects to restore...
Restored /Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/FunctionsMcpTool.csproj (in 5.14 sec).
/Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/SnippetsTool.cs(8,49): warning CS9113: Parameter 'logger' is unread. [/Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/FunctionsMcpTool.csproj]
Determining projects to restore...
Restored /Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/obj/Debug/net8.0/WorkerExtensions/WorkerExtensions.csproj (in 4.13 sec).
WorkerExtensions -> /Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/obj/Debug/net8.0/WorkerExtensions/buildout/Microsoft.Azure.Functions.Worker.Extensions.dll
FunctionsMcpTool -> /Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/bin/output/FunctionsMcpTool.dll
Build succeeded.
/Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/SnippetsTool.cs(8,49): warning CS9113: Parameter 'logger' is unread. [/Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/FunctionsMcpTool.csproj]
1 Warning(s)
0 Error(s)
Time Elapsed 00:00:14.60
Azure Functions Core Tools
Core Tools Version: 4.0.7030 Commit hash: N/A +bb4c949899cd5659d6bfe8b92cc923453a2e8f88 (64-bit)
Function Runtime Version: 4.1037.0.23568
[2025-04-21T20:23:24.563Z] Found /Users/iwasa.takahito/work/hoge0422azurefunc/remote-mcp-functions-dotnet/src/FunctionsMcpTool.csproj. Using for user secrets file configuration.
[2025-04-21T20:23:25.375Z] MCP server SSE endpoint: http://localhost:7071/runtime/webhooks/mcp/sse
[2025-04-21T20:23:27.225Z] Worker process started and initialized.
Functions:
GetSnippet: mcpToolTrigger
SaveSnippet: mcpToolTrigger
SayHello: mcpToolTrigger
For detailed output, run func with --verbose flag.
[2025-04-21T20:23:32.267Z] Host lock lease acquired by instance ID '000000000000000000000000BA677196'.
ローカル実行が出来ました。
MCP サーバーの SSE エンドポイントが払い出されたので、試しに普段使っている Claude Desktop に設定してみました。
知らなかったのですが、Claude Desktop では SSE エンドポイントを直接設定出来ないのでmcp-remote
を使う必要があるようなのでこちらの方法を使ってみました。
{
"mcpServers": {
"Azure Functions Local": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:7071/runtime/webhooks/mcp/sse"
]
}
}
}
このサンプル MCP サーバーではget_snippets
、hello
、save_snippet
が用意されてます。
Claude Desktop が直接 SSE エンドポイントを設定出来なかったので、以降は MCP Inspector を使って動作の確認をしてみたいと思います。ローカルエンドポイントについては次のように確認が出来ました。
Azure での実行
ローカルで動作確認が出来たので、今度は Azure 上にデプロイして動作確認してみましょう。
Azure Developer CLI (azd) を使ってデプロイします。
% azd auth login
Logged in to Azure as admin@aad.tak1wa.com
% azd up
(✓) Done: Downloading Bicep
? Select an Azure Subscription to use: 1. hoge subscription (a50aeedb-979c-428f-8b2d-28974d5e3d3b)
? Enter a value for the 'location' infrastructure parameter: 7. (US) East US (eastus)
? Enter a value for the 'vnetEnabled' infrastructure parameter: False
Packaging services (azd package)
(✓) Done: Packaging service api
- Package Output: /var/folders/4d/nhd1bp3d161crsn900wjrprm0000gp/T/remote-mcp-functions-dotnet-api-azddeploy-1745267851.zip
Provisioning Azure resources (azd provision)
Provisioning Azure resources can take some time.
Subscription: hoge subscription (a50aeedb-979c-428f-8b2d-28974d5e3d3b)
Location: East US
You can view detailed progress in the Azure Portal:
https://portal.azure.com/#view/HubsExtension/DeploymentDetailsBlade/~/overview/id/%2Fsubscriptions%2Fa50aeedb-979c-428f-8b2d-28974d5e3d3b%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Fhoge0422-1745267855
(✓) Done: Resource group: rg-hoge0422 (5.232s)
(✓) Done: App Service plan: plan-tehexyshtiewy (9.582s)
(✓) Done: Storage account: sttehexyshtiewy (23.55s)
(✓) Done: Log Analytics workspace: log-tehexyshtiewy (19.404s)
(✓) Done: Application Insights: appi-tehexyshtiewy (4.844s)
(✓) Done: Function App: func-api-tehexyshtiewy (25.778s)
Deploying services (azd deploy)
(✓) Done: Deploying service api
- Endpoint: https://func-api-tehexyshtiewy.azurewebsites.net/
SUCCESS: Your up workflow to provision and deploy to Azure completed in 2 minutes 31 seconds.
先ほどのローカル時はhttp://localhost:7071/runtime/webhooks/mcp/sse
というエンドポイントでしたが、上記発行されたエンドポイントに置き換えましょう。SSE でいうとhttps://func-api-tehexyshtiewy.azurewebsites.net/runtime/webhooks/mcp/sse
ですね。
また、Azure Functions へのアクセスの際にキーを使用します。
mcp_extension というキーが発行されているはずなので、こちらを使います。
MCP Inspector から使ってみると、Azure Functions 上のリモート MCP サーバーに接続してツールを実行することが出来ました。
コードも見てみる
ついでにサンプルコードを見てみましょう。
ツールの定義やディスクリプションですが、内容自体はこちらに定義されています。
namespace FunctionsSnippetTool;
internal sealed class ToolsInformation
{
public const string SaveSnippetToolName = "save_snippet";
public const string SaveSnippetToolDescription =
"Saves a code snippet into your snippet collection.";
public const string GetSnippetToolName = "get_snippets";
public const string GetSnippetToolDescription =
"Gets code snippets from your snippet collection.";
public const string SnippetNamePropertyName = "snippetname";
public const string SnippetPropertyName = "snippet";
public const string SnippetNamePropertyDescription = "The name of the snippet.";
public const string SnippetPropertyDescription = "The code snippet.";
public const string PropertyType = "string";
public const string HelloToolName = "hello";
public const string HelloToolDescription =
"Simple hello world MCP Tool that responses with a hello message.";
}
そして、関数側ではMcpToolTrigger
として使用しています。
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Mcp;
using Microsoft.Extensions.Logging;
using static FunctionsSnippetTool.ToolsInformation;
namespace FunctionsSnippetTool;
public class HelloTool(ILogger<SnippetsTool> logger)
{
[Function(nameof(SayHello))]
public string SayHello(
[McpToolTrigger(HelloToolName, HelloToolDescription)] ToolInvocationContext context
)
{
logger.LogInformation("Saying hello");
return "Hello I am MCP Tool!";
}
}
さいごに
本日は Azure Functions をリモート MCP サーバーとして使えるようになったので試してみました。
サンプル実行しただけはあるのですが、コードを見た感じでもかなり簡単にリモート MCP サーバーをサーバーレスで用意できますね。
まだプレビューではありますが、色々触ってみたいと思います。