@deplens/mcp 0.1.0

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.
Files changed (2) hide show
  1. package/package.json +26 -0
  2. package/src/server.mjs +111 -0
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@deplens/mcp",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./src/server.mjs",
6
+ "bin": {
7
+ "deplens-mcp": "./src/server.mjs"
8
+ },
9
+ "files": [
10
+ "src"
11
+ ],
12
+ "scripts": {
13
+ "build": "echo 'no build'"
14
+ },
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "dependencies": {
19
+ "@deplens/core": "0.1.0",
20
+ "@modelcontextprotocol/sdk": "^1.25.1"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "license": "MIT"
26
+ }
package/src/server.mjs ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
+ import { runInspect } from "@deplens/core";
6
+
7
+ const tools = [
8
+ {
9
+ name: "deplens.inspect",
10
+ description: "Inspect exports and types for an installed npm package.",
11
+ inputSchema: {
12
+ type: "object",
13
+ properties: {
14
+ target: { type: "string", description: "Package name or import path (e.g. react, next/server)" },
15
+ subpath: { type: "string", description: "Optional subpath (e.g. server for next/server)" },
16
+ filter: { type: "string", description: "Substring filter for exports" },
17
+ kind: {
18
+ type: "array",
19
+ items: { type: "string", enum: ["function", "class", "object", "constant", "interface", "type"] },
20
+ description: "Filter by export kind",
21
+ },
22
+ showTypes: { type: "boolean", description: "Show type signatures from .d.ts" },
23
+ depth: { type: "number", description: "Depth for object inspection (0-5)" },
24
+ resolveFrom: { type: "string", description: "Base directory for module resolution" },
25
+ rootDir: { type: "string", description: "Working directory for the inspection (default: cwd)" },
26
+ jsdoc: { type: "string", enum: ["off", "compact", "full"], description: "JSDoc mode" },
27
+ jsdocOutput: {
28
+ type: "string",
29
+ enum: ["off", "section", "inline", "only"],
30
+ description: "Where to print JSDoc",
31
+ },
32
+ jsdocQuery: {
33
+ type: "object",
34
+ properties: {
35
+ symbols: {
36
+ oneOf: [
37
+ { type: "string" },
38
+ { type: "array", items: { type: "string" } }
39
+ ]
40
+ },
41
+ sections: {
42
+ type: "array",
43
+ items: { type: "string", enum: ["summary", "params", "returns", "tags"] }
44
+ },
45
+ tags: {
46
+ type: "object",
47
+ properties: {
48
+ include: { type: "array", items: { type: "string" } },
49
+ exclude: { type: "array", items: { type: "string" } }
50
+ }
51
+ },
52
+ mode: { type: "string", enum: ["compact", "full"] },
53
+ maxLen: { type: "number" },
54
+ truncate: { type: "string", enum: ["none", "sentence", "word"] }
55
+ }
56
+ }
57
+ },
58
+ required: ["target"]
59
+ }
60
+ }
61
+ ];
62
+
63
+ const server = new Server(
64
+ { name: "deplens", version: "0.1.0" },
65
+ { capabilities: { tools: {} } }
66
+ );
67
+
68
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
69
+ return { tools };
70
+ });
71
+
72
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
73
+ const { name, arguments: args } = request.params;
74
+ try {
75
+ if (name !== "deplens.inspect") {
76
+ throw new Error(`Unknown tool: ${name}`);
77
+ }
78
+
79
+ const rootDir = args?.rootDir || process.env.DEPLENS_ROOT || process.cwd();
80
+ const target = args?.subpath ? `${args.target}/${args.subpath}` : args?.target;
81
+ if (!target) throw new Error("Missing required field: target");
82
+
83
+ const output = await runInspect({
84
+ target,
85
+ filter: args?.filter,
86
+ showTypes: args?.showTypes,
87
+ jsdoc: args?.jsdoc,
88
+ jsdocOutput: args?.jsdocOutput,
89
+ jsdocQuery: args?.jsdocQuery,
90
+ kind: args?.kind,
91
+ depth: args?.depth,
92
+ resolveFrom: args?.resolveFrom,
93
+ cwd: rootDir,
94
+ });
95
+
96
+ return { content: [{ type: "text", text: output }] };
97
+ } catch (error) {
98
+ const message = error instanceof Error ? error.message : String(error);
99
+ return { content: [{ type: "text", text: `Error: ${message}` }], isError: true };
100
+ }
101
+ });
102
+
103
+ async function main() {
104
+ const transport = new StdioServerTransport();
105
+ await server.connect(transport);
106
+ }
107
+
108
+ main().catch((error) => {
109
+ console.error("Server error:", error);
110
+ process.exit(1);
111
+ });