Open4
Workers , remote MCP Server 作成 JSON-RPC 2.0
概要
- Workers , remote MCP Server メモです。
- json-rpc 2.0 で、操作します
[ 公開 2025/10/17 ]
環境
- Cloudflare Workers
- node 22
- MCP Server
参考したコード
- dev-start
npm run dev
- settings.json : GEMINI-CLI
- httpUrl: mcpのエンドポイント
"myRemoteServer": {
"httpUrl": "http://localhost:8787",
"headers": {
"Authorization": ""
},
"timeout": 5000
}
- 入力文
Get current server time
- 実行結果の確認
- time 返却される

- test-code
- tools/list
- test1.js
const start = async function() {
try{
const item = {
"jsonrpc": "2.0",
"method": "tools/list",
"id": 1
}
const response = await fetch("http://localhost:8787", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': '',
},
body: JSON.stringify(item),
});
if (!response.ok) {
const text = await response.text();
console.log(text);
throw new Error('Failed to create item');
}else{
console.log("OK");
const json = await response.json();
console.log(json);
console.log(json.result);
}
}catch(e){console.log(e)}
}
start();
- test2.js
- tools/call
const start = async function() {
try{
const item = {
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_time",
"arguments": {}
},
"id": 2
}
const response = await fetch("http://localhost:8787", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': '',
},
body: JSON.stringify(item),
});
if (!response.ok) {
const text = await response.text();
console.log(text);
throw new Error('Failed to create item');
}else{
console.log("OK");
const json = await response.json();
console.log(json);
console.log(json.result.content[0].text);
}
}catch(e){console.log(e)}
}
start();
- 購入品の 登録 , TURSO Database の例を追加
- 入力文の例
お茶 120 円 をAPIに送信して欲しい

Electron, client 画面追加しました。

-
購入品リスト ,表示機能を追加しました。 remote MCP Server
-
入力文の例
購入品リストを、表示して欲しい
