@nick-vi/type-inject-mcp 1.0.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/dist/index.js +114 -0
  2. package/package.json +29 -0
package/dist/index.js ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
+ import { z } from "zod";
7
+ import {
8
+ TypeLookup,
9
+ defaultConfig
10
+ } from "@nick-vi/type-inject-core";
11
+ var cwd = process.cwd();
12
+ var typeLookup = null;
13
+ function getTypeLookup() {
14
+ if (!typeLookup) {
15
+ typeLookup = new TypeLookup(cwd, defaultConfig);
16
+ }
17
+ return typeLookup;
18
+ }
19
+ var server = new McpServer({
20
+ name: "type-inject",
21
+ version: "0.1.0"
22
+ });
23
+ var kindEnum = z.enum(["function", "type", "interface", "enum", "class", "const"]);
24
+ server.registerTool("lookup_type", {
25
+ title: "Lookup Type",
26
+ description: "Look up TypeScript type definitions by name. Returns the full type signature, file location, and optionally where it's used.",
27
+ inputSchema: {
28
+ name: z.string(),
29
+ exact: z.boolean().optional(),
30
+ kind: z.array(kindEnum).optional(),
31
+ includeUsages: z.boolean().optional(),
32
+ limit: z.number().optional()
33
+ }
34
+ }, async ({ name, exact, kind, includeUsages, limit }) => {
35
+ const lookup = getTypeLookup();
36
+ const result = lookup.findType(name, {
37
+ exact: exact ?? true,
38
+ kind,
39
+ includeUsages: includeUsages ?? false,
40
+ limit: limit ?? 5
41
+ });
42
+ if (!result.found) {
43
+ return { content: [{ type: "text", text: `No types found matching "${name}"` }] };
44
+ }
45
+ const lines = [];
46
+ lines.push(`Found ${result.totalMatches} type(s) matching "${name}" (showing ${result.types.length}):`);
47
+ lines.push("");
48
+ for (const type of result.types) {
49
+ lines.push(`## ${type.name} (${type.kind})`);
50
+ const offset = type.line - 1;
51
+ const lineLimit = type.lineEnd - type.line + 1;
52
+ lines.push(`File: ${type.relativePath} [offset=${offset},limit=${lineLimit}]`);
53
+ if (type.exported)
54
+ lines.push("Exported: yes");
55
+ if (type.jsdoc)
56
+ lines.push(`JSDoc: ${type.jsdoc}`);
57
+ if (type.generics?.length) {
58
+ lines.push(`Generics: <${type.generics.join(", ")}>`);
59
+ }
60
+ lines.push("");
61
+ lines.push("```typescript");
62
+ lines.push(type.signature);
63
+ lines.push("```");
64
+ if (type.usedIn?.length) {
65
+ lines.push("");
66
+ lines.push(`Used in ${type.usedIn.length} file(s):`);
67
+ for (const usage of type.usedIn.slice(0, 10)) {
68
+ lines.push(` - ${usage.relativePath}:${usage.line}`);
69
+ }
70
+ if (type.usedIn.length > 10) {
71
+ lines.push(` ... and ${type.usedIn.length - 10} more`);
72
+ }
73
+ }
74
+ lines.push("");
75
+ }
76
+ if (result.totalMatches > result.types.length) {
77
+ lines.push(`(${result.totalMatches - result.types.length} more results not shown)`);
78
+ }
79
+ lines.push(`Search time: ${result.searchTimeMs}ms`);
80
+ if (result.indexBuilt) {
81
+ lines.push("(Index was built during this query)");
82
+ }
83
+ return { content: [{ type: "text", text: lines.join(`
84
+ `) }] };
85
+ });
86
+ server.registerTool("list_types", {
87
+ title: "List Types",
88
+ description: "List all TypeScript type names in the project. Useful for discovering available types.",
89
+ inputSchema: {
90
+ kind: z.array(kindEnum).optional(),
91
+ limit: z.number().optional()
92
+ }
93
+ }, async ({ kind, limit }) => {
94
+ const lookup = getTypeLookup();
95
+ const results = lookup.listTypeNames({
96
+ kind,
97
+ limit: limit ?? 100
98
+ });
99
+ if (results.length === 0) {
100
+ return { content: [{ type: "text", text: "No types found in the project" }] };
101
+ }
102
+ const stats = lookup.getStats();
103
+ const lines = [];
104
+ lines.push(`Found ${stats.totalTypes} types in ${stats.totalFiles} files. Showing ${results.length}:`);
105
+ lines.push("");
106
+ lines.push(results.map((r) => `${r.name} (${r.kind})`).join(", "));
107
+ return { content: [{ type: "text", text: lines.join(`
108
+ `) }] };
109
+ });
110
+ async function main() {
111
+ const transport = new StdioServerTransport;
112
+ await server.connect(transport);
113
+ }
114
+ main().catch(console.error);
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@nick-vi/type-inject-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for TypeScript type lookup",
5
+ "type": "module",
6
+ "bin": {
7
+ "type-inject-mcp": "dist/index.js"
8
+ },
9
+ "files": ["dist/"],
10
+ "scripts": {
11
+ "build": "bun build src/index.ts --outdir dist --target node --format esm --packages external",
12
+ "typecheck": "tsc --noEmit",
13
+ "prepare": "npm run build"
14
+ },
15
+ "dependencies": {
16
+ "@modelcontextprotocol/sdk": "^1.0.0",
17
+ "@nick-vi/type-inject-core": "1.0.2",
18
+ "zod": "^4.3.5"
19
+ },
20
+ "peerDependencies": {
21
+ "typescript": "^5"
22
+ },
23
+ "devDependencies": {
24
+ "@types/bun": "latest"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }