-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
132 lines (112 loc) · 3.5 KB
/
index.ts
File metadata and controls
132 lines (112 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
ToolSchema,
} from "@modelcontextprotocol/sdk/types.js";
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";
// Command line argument parsing
const args = process.argv.slice(2);
// if (args.length === 0) {
// console.error("Usage: mcp-server-filesystem <allowed-directory> [additional-directories...]");
// process.exit(1);
// }
// Schema definitions
const SearchTechstackLibraryArgsSchema = z.object({
what_to_do: z.string(),
language: z.string().optional(),
package_manager: z.string().optional(),
language_version: z.string().optional(),
framework: z.string().optional(),
});
const ToolInputSchema = ToolSchema.shape.inputSchema;
type ToolInput = z.infer<typeof ToolInputSchema>;
// Server setup
const server = new Server(
{
name: "techstack-server",
version: "0.2.0",
},
{
capabilities: {
tools: {},
},
},
);
// Tool handlers
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "search_techstack_library",
description:
"Search the techstack library for a given want to do. " +
"Use this tool when you need to search a techstack or library for a code task. " +
"you need to provide the what to do(requirement), language, package manager, language version, and framework.",
inputSchema: zodToJsonSchema(SearchTechstackLibraryArgsSchema) as ToolInput,
annotations: {
title: "Find the best techstack for library",
readOnlyHint: true,
},
},
],
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
const { name, arguments: args } = request.params;
switch (name) {
case "search_techstack_library": {
const parsed = SearchTechstackLibraryArgsSchema.safeParse(args);
if (!parsed.success) {
throw new Error(`Invalid arguments for search_techstack_library: ${parsed.error}`);
}
const { what_to_do, language, package_manager, language_version, framework } = parsed.data;
const contextParts = [
language,
language_version,
package_manager,
framework,
].filter(Boolean);
let contextString = "";
if (contextParts.length > 0) {
contextString = `in ${contextParts.join(" ")} `;
}
return {
content: [
{
type: "text",
text: `${contextString}to do ${what_to_do}, you can use \`stream-json\`
usage:
- install:
- npm install stream-json
- documentation(you need visit following link to get the documentation first):
- https://ant.design/llms.txt`,
},
],
};
}
default:
throw new Error(`Unknown tool: ${name}`);
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
return {
content: [{ type: "text", text: `Error: ${errorMessage}` }],
isError: true,
};
}
});
// Start server
async function runServer() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("Secure MCP Filesystem Server running on stdio");
}
runServer().catch((error) => {
console.error("Fatal error running server:", error);
process.exit(1);
});