Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created October 16, 2025 22:39
Show Gist options
  • Save kuc-arc-f/66c6ac29fe229e4ba495acb1ca14f196 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/66c6ac29fe229e4ba495acb1ca14f196 to your computer and use it in GitHub Desktop.
test-code , Rust remote MCP Server , example
const start = async function() {
try{
const item = {
"jsonrpc": "2.0",
"method": "tools/list",
"id": 2
}
const response = await fetch("http://localhost:3000/mcp", {
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{
const json = await response.json();
console.log(json);
console.log(json.result.tools);
}
}catch(e){console.log(e)}
}
start();
const start = async function() {
try{
const item = {
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "purchase",
"arguments": {name: "tea", price: 170}
},
"id": 2
}
const response = await fetch("http://localhost:3000/mcp", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': "xyz-abcdef-1234567890",
},
body: JSON.stringify(item),
});
if (!response.ok) {
const text = await response.text();
console.log(text);
throw new Error('Failed to create item');
}else{
const json = await response.json();
console.log(json);
console.log("text=", json.result.content[0].text);
}
}catch(e){console.log(e)}
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment