💡

忙しい人のためのMCPまとめ

に公開

ざっくりMCPとは何か?

MCPはLLMが使う道具の標準規格

MCPは何の略ですか?

Model Context Protocol

MCPは誰が考えたものですか?

2024年末にAnthropic社が発表

参考
https://www.anthropic.com/news/model-context-protocol

ざっくり作り方を知りたいです

システム構成図

参考
https://modelcontextprotocol.io/introduction

実際のコードイメージ

src/index.ts
// import文など

// 初期設定
const server = new McpServer({
  name: "weather",
  version: "1.0.0",
  capabilities: {
    resources: {},
    tools: {},
  },
});

// 実際にできることを書く
server.tool(
  "get-forecast",
  "Get weather forecast for a location",
  {
    latitude: z.number().min(-90).max(90).describe("Latitude of the location"),
    longitude: z.number().min(-180).max(180).describe("Longitude of the location"),
  },
  async ({ latitude, longitude }) => {

    };
);

server.tool()は
第一引数:ツールの名前
第二引数:ツールの説明
第三引数:リクエスト内容
第四引数:具体的な処理

参考
https://modelcontextprotocol.io/quickstart/server

実際のClaudeの画面

実際にツールが読み込まれている様子

実際にツールを利用して見た様子

おすすめのZenn

もう少し時間がある人におすすめ
https://zenn.dev/mkj/articles/0ed4d02ef3439c

デザインとの連携に興味がある人におすすめ
https://zenn.dev/ubie_dev/articles/f927aaff02d618

クリプトに興味がある人におすすめ
https://www.foxytanuki.dev/learn-mcp

Discussion