Home
back

MCP Client 作成 調査, Ollama

id: 190, 2025-05-23

### 音声概要

・AIで生成された 音声概要になります。


### 概要

  • MCP Clientの 調査メモになります。
  • Ollama ローカルLLM を使用します。
  • MCP Client作成に難航した為、関連記事を参考にしました。
  • 作業PCは、RAM 32GB、CPU (GPUなし)
  • 無課金で使用可能です (PCの、電気代の出費あります。)

[ 公開 2025/04/19 ]


### 関連の記事


### 環境

  • node 20
  • windows 11

### 感想

  • ローカルLLM 環境で、処理は遅めでしたが。
  • 短い、プロンプトでは。30秒位で処理できました。
  • MCPの連続テストでも、無課金で使用できそうでした。

### MCP Server , 外部API連携

  • 上記の、MCP クライアント参考に。 MCP Serverを追加。
  • 外部APIの、接続URL は。.env から取得します。
  • d1 databaseに、データ保存します

### 書いたコード


  • src/mcp-2ex-test.ts
  • クライアントから、MCP Server設定を追加します。
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import "dotenv/config"
console.log("API_URL=", process.env.API_URL);

const server = new McpServer({
  name: "mcp-2ex",
  version: "1.0.0",
});

server.tool(
  "mcp-2ex-test",
  `指定した 文字列を登録する。`,
  {
    text: z.string().min(1, { message: "タイトルは必須です" })
  },
  async ({text}) => {
    try{
      const url = process.env.API_URL;
      const item = {title: text, description:"" }
      const response = await fetch(url + "/api/todos/create" ,
        {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify(item),
        }
      );
      if(response.ok === false){
        throw new Error("Error, response <> OK:");
      }
      const body = await response.text();
      return {
        content: [
          {
            type: "text",
            text: body,
          },
        ],
      };
    }catch(e){
      throw new Error("Error, mcp-2ex-test:" + e);
    }

  }
);

export const Mcp2exTestServer = server;

### Test

  • プロンプトは、下記です、
  • todoを、d1に保存。
mcp-2ex-test を使って、お茶を購入して。休憩する を送信して欲しい。

### MCP Client 作成、Electron + Ollama版

  • electron で、MCP クライアント作成メモです。
  • 外部APIの、接続URL は。.env から取得します。
  • d1 databaseに、データ保存します

### 書いたコード


### 操作

  • model 選択 : qwen2.5-coder:14b(右上) プルダウン

  • プロンプト参考
mcp-2ex-test を使って、お茶を購入して。休憩する を送信して欲しい。

  • MCP server
  • mcp-client-ui/src/mcp-servers/mcp-2ex-test.ts

https://github.com/kuc-arc-f/mcp_client_1ex/blob/main/mcp-client-ui/src/mcp-servers/mcp-2ex-test.ts


  • home画面
  • mcp-client-ui/src/client/home.tsx

https://github.com/kuc-arc-f/mcp_client_1ex/blob/main/mcp-client-ui/src/client/home.tsx