@victox/hello-stdio 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1 -3
- package/dist/index.mjs +2 -59
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,59 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
|
|
5
|
-
//#region ../hello-lib/dist/index.js
|
|
6
|
-
const GREETINGS = [
|
|
7
|
-
"Hello!",
|
|
8
|
-
"Hi there!",
|
|
9
|
-
"Hey!",
|
|
10
|
-
"Howdy!",
|
|
11
|
-
"Good day!",
|
|
12
|
-
"Greetings!"
|
|
13
|
-
];
|
|
14
|
-
function pickRandom(items) {
|
|
15
|
-
if (items.length === 0) throw new Error("pickRandom: empty list");
|
|
16
|
-
return items[Math.floor(Math.random() * items.length)];
|
|
17
|
-
}
|
|
18
|
-
function registerHelloTools(server) {
|
|
19
|
-
server.registerTool("hello1", { description: "Generate a random greeting." }, async () => {
|
|
20
|
-
return { content: [{
|
|
21
|
-
type: "text",
|
|
22
|
-
text: pickRandom(GREETINGS)
|
|
23
|
-
}] };
|
|
24
|
-
});
|
|
25
|
-
server.registerTool("hello2", {
|
|
26
|
-
description: "Generate a greeting addressed to a provided name.",
|
|
27
|
-
inputSchema: { name: z.string().min(1).describe("Name to greet.") }
|
|
28
|
-
}, async ({ name }) => {
|
|
29
|
-
return { content: [{
|
|
30
|
-
type: "text",
|
|
31
|
-
text: `${pickRandom(GREETINGS)} ${name}`
|
|
32
|
-
}] };
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function createHelloServer(info, options) {
|
|
36
|
-
const server = new McpServer(info, options);
|
|
37
|
-
registerHelloTools(server);
|
|
38
|
-
return server;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/index.ts
|
|
43
|
-
async function main() {
|
|
44
|
-
const mcpServer = createHelloServer({
|
|
45
|
-
name: "hello-mcp-server",
|
|
46
|
-
version: "0.1.0"
|
|
47
|
-
});
|
|
48
|
-
const transport = new StdioServerTransport();
|
|
49
|
-
await mcpServer.connect(transport);
|
|
50
|
-
}
|
|
51
|
-
if (process.stdin.isTTY) process.stdin.resume();
|
|
52
|
-
main().catch((err) => {
|
|
53
|
-
const message = err instanceof Error ? err.stack ?? err.message : String(err);
|
|
54
|
-
process.stderr.write(message + "\n");
|
|
55
|
-
process.exit(1);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
export { };
|
|
1
|
+
import{McpServer as e}from"@modelcontextprotocol/sdk/server/mcp.js";import*as t from"zod/v4";import{StdioServerTransport as n}from"@modelcontextprotocol/sdk/server/stdio.js";const r=[`Hello!`,`Hi there!`,`Hey!`,`Howdy!`,`Good day!`,`Greetings!`];function i(e){if(e.length===0)throw Error(`pickRandom: empty list`);return e[Math.floor(Math.random()*e.length)]}function a(e){e.registerTool(`hello1`,{description:`Generate a random greeting.`},async()=>({content:[{type:`text`,text:i(r)}]})),e.registerTool(`hello2`,{description:`Generate a greeting addressed to a provided name.`,inputSchema:{name:t.string().min(1).describe(`Name to greet.`)}},async({name:e})=>({content:[{type:`text`,text:`${i(r)} ${e}`}]}))}function o(t,n){let r=new e(t,n);return a(r),r}async function s(){let e=o({name:`hello-mcp-server`,version:`0.1.0`}),t=new n;await e.connect(t)}process.stdin.isTTY&&process.stdin.resume(),s().catch(e=>{let t=e instanceof Error?e.stack??e.message:String(e);process.stderr.write(t+`
|
|
2
|
+
`),process.exit(1)});export{};
|