もくじ
https://tera1707.com/entry/2022/02/06/144447
やりたいこと
MCPサーバーの3大プリミティブ(基本機能)の
- ツール
- プロンプト
- リソース
を試したい。
今回は「リソース」をやる。
サンプルコード
下記のリポジトリで、ツール、プロンプト、リソースを実験した。
その中で、リソースはここ。
<feff>using ModelContextProtocol.Server; using System.ComponentModel; namespace ReviewWithOurCodingRulesMcpServer; [McpServerResourceType] internal static class CodingRuleWebPageResources { [McpServerResource, Description("私たちのC#コーディングルールが記載されたwebページのURL")] public static string GetOurCsCodingRuleWebPageURL() => "https://tera1707.com/entry/2025/07/20/235616"; [McpServerResource, Description("私たちのC++コーディングルールが記載されたwebページのURL")] public static string GetOurCppCodingRuleWebPageURL() => "https://tera1707.com/entry/2025/07/20/230051"; }
メイン部分に、.WithResourcesFromAssembly()を追記する。
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using ModelContextProtocol; using System.Net.Http.Headers; var builder = Host.CreateEmptyApplicationBuilder(settings: null); builder.Services.AddMcpServer() .WithStdioServerTransport() .WithResourcesFromAssembly() .WithPromptsFromAssembly() .WithToolsFromAssembly(); var app = builder.Build(); await app.RunAsync();
こう書いておくと、vscodeでは、[コンテキストの追加] > [MCPリソース]から、そのリソースをコンテキストとして選べるようになる。

👇これ。

備考
github公式のMCpサーバーの作り方などを見ても、リソースの作り方というのは見当たらなかった。(探し方が足りないだけかも?)
使った感じでも、「劇的に便利!」という使い方もパッとは思いつかなかったので、まだ人気が無い機能なのかもしれない。
参考
GitHub Copilot Agent Mode の MCP の Tools, Prompts, Resources の使い方
現状一番わかりやすい解説