Created
October 16, 2025 22:39
-
-
Save kuc-arc-f/66c6ac29fe229e4ba495acb1ca14f196 to your computer and use it in GitHub Desktop.
test-code , Rust remote MCP Server , example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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