@topgunbuild/mcp-server 0.9.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.
- package/LICENSE +97 -0
- package/README.md +199 -0
- package/dist/cli.js +1695 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.mts +410 -0
- package/dist/index.d.ts +410 -0
- package/dist/index.js +1513 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1495 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { TopGunClient } from '@topgunbuild/client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TopGun MCP Server Types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for the MCP server
|
|
10
|
+
*/
|
|
11
|
+
interface MCPServerConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Name of the MCP server (shown to AI clients)
|
|
14
|
+
* @default 'topgun-mcp-server'
|
|
15
|
+
*/
|
|
16
|
+
name?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Version of the MCP server
|
|
19
|
+
* @default '1.0.0'
|
|
20
|
+
*/
|
|
21
|
+
version?: string;
|
|
22
|
+
/**
|
|
23
|
+
* TopGun client instance to use
|
|
24
|
+
* If not provided, a new client will be created with topgunUrl
|
|
25
|
+
*/
|
|
26
|
+
client?: TopGunClient;
|
|
27
|
+
/**
|
|
28
|
+
* TopGun server URL (WebSocket)
|
|
29
|
+
* Used when client is not provided
|
|
30
|
+
* @default 'ws://localhost:8080'
|
|
31
|
+
*/
|
|
32
|
+
topgunUrl?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Authentication token for TopGun server
|
|
35
|
+
*/
|
|
36
|
+
authToken?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Restrict available maps (if not specified, all maps are available)
|
|
39
|
+
*/
|
|
40
|
+
allowedMaps?: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Enable mutation tools (set, remove)
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
enableMutations?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Enable subscription tools
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
enableSubscriptions?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Default limit for query results
|
|
53
|
+
* @default 10
|
|
54
|
+
*/
|
|
55
|
+
defaultLimit?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Maximum limit for query results
|
|
58
|
+
* @default 100
|
|
59
|
+
*/
|
|
60
|
+
maxLimit?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Subscription timeout in seconds
|
|
63
|
+
* @default 60
|
|
64
|
+
*/
|
|
65
|
+
subscriptionTimeoutSeconds?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Enable debug logging
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
debug?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolved configuration with all defaults applied
|
|
74
|
+
*/
|
|
75
|
+
interface ResolvedMCPServerConfig {
|
|
76
|
+
name: string;
|
|
77
|
+
version: string;
|
|
78
|
+
topgunUrl: string;
|
|
79
|
+
authToken?: string;
|
|
80
|
+
allowedMaps?: string[];
|
|
81
|
+
enableMutations: boolean;
|
|
82
|
+
enableSubscriptions: boolean;
|
|
83
|
+
defaultLimit: number;
|
|
84
|
+
maxLimit: number;
|
|
85
|
+
subscriptionTimeoutSeconds: number;
|
|
86
|
+
debug: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* MCP Tool definition
|
|
90
|
+
*/
|
|
91
|
+
interface MCPTool {
|
|
92
|
+
name: string;
|
|
93
|
+
description: string;
|
|
94
|
+
inputSchema: {
|
|
95
|
+
type: 'object';
|
|
96
|
+
properties: Record<string, unknown>;
|
|
97
|
+
required?: string[];
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* MCP Tool call result
|
|
102
|
+
*/
|
|
103
|
+
interface MCPToolResult {
|
|
104
|
+
content: Array<{
|
|
105
|
+
type: 'text' | 'image' | 'resource';
|
|
106
|
+
text?: string;
|
|
107
|
+
data?: string;
|
|
108
|
+
mimeType?: string;
|
|
109
|
+
}>;
|
|
110
|
+
isError?: boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Query tool arguments
|
|
114
|
+
*/
|
|
115
|
+
interface QueryToolArgs {
|
|
116
|
+
map: string;
|
|
117
|
+
filter?: Record<string, unknown>;
|
|
118
|
+
sort?: {
|
|
119
|
+
field: string;
|
|
120
|
+
order: 'asc' | 'desc';
|
|
121
|
+
};
|
|
122
|
+
limit?: number;
|
|
123
|
+
offset?: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Mutate tool arguments
|
|
127
|
+
*/
|
|
128
|
+
interface MutateToolArgs {
|
|
129
|
+
map: string;
|
|
130
|
+
operation: 'set' | 'remove';
|
|
131
|
+
key: string;
|
|
132
|
+
data?: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Search tool arguments
|
|
136
|
+
*/
|
|
137
|
+
interface SearchToolArgs {
|
|
138
|
+
map: string;
|
|
139
|
+
query: string;
|
|
140
|
+
methods?: Array<'exact' | 'fulltext' | 'range'>;
|
|
141
|
+
limit?: number;
|
|
142
|
+
minScore?: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Subscribe tool arguments
|
|
146
|
+
*/
|
|
147
|
+
interface SubscribeToolArgs {
|
|
148
|
+
map: string;
|
|
149
|
+
filter?: Record<string, unknown>;
|
|
150
|
+
timeout?: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Schema tool arguments
|
|
154
|
+
*/
|
|
155
|
+
interface SchemaToolArgs {
|
|
156
|
+
map: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Stats tool arguments
|
|
160
|
+
*/
|
|
161
|
+
interface StatsToolArgs {
|
|
162
|
+
map?: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Explain tool arguments
|
|
166
|
+
*/
|
|
167
|
+
interface ExplainToolArgs {
|
|
168
|
+
map: string;
|
|
169
|
+
filter?: Record<string, unknown>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* List maps tool arguments (no args required)
|
|
173
|
+
*/
|
|
174
|
+
interface ListMapsToolArgs {
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Tool execution context
|
|
178
|
+
*/
|
|
179
|
+
interface ToolContext {
|
|
180
|
+
client: TopGunClient;
|
|
181
|
+
config: ResolvedMCPServerConfig;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* TopGun MCP Server
|
|
186
|
+
*
|
|
187
|
+
* Model Context Protocol server for TopGun database.
|
|
188
|
+
* Enables AI assistants (Claude, Cursor) to interact with TopGun data.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* TopGun MCP Server
|
|
193
|
+
*
|
|
194
|
+
* Provides MCP protocol interface for AI assistants to interact
|
|
195
|
+
* with TopGun databases.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const server = new TopGunMCPServer({
|
|
200
|
+
* topgunUrl: 'ws://localhost:8080',
|
|
201
|
+
* allowedMaps: ['tasks', 'users'],
|
|
202
|
+
* });
|
|
203
|
+
*
|
|
204
|
+
* await server.start();
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare class TopGunMCPServer {
|
|
208
|
+
private readonly server;
|
|
209
|
+
private readonly client;
|
|
210
|
+
private readonly config;
|
|
211
|
+
private readonly toolContext;
|
|
212
|
+
private readonly logger;
|
|
213
|
+
private isStarted;
|
|
214
|
+
private externalClient;
|
|
215
|
+
constructor(config?: MCPServerConfig);
|
|
216
|
+
/**
|
|
217
|
+
* Register MCP protocol handlers
|
|
218
|
+
*/
|
|
219
|
+
private registerHandlers;
|
|
220
|
+
/**
|
|
221
|
+
* Start the MCP server with stdio transport
|
|
222
|
+
*/
|
|
223
|
+
start(): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Start the MCP server with a custom transport
|
|
226
|
+
*/
|
|
227
|
+
startWithTransport(transport: {
|
|
228
|
+
start(): Promise<void>;
|
|
229
|
+
}): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Stop the server and cleanup resources
|
|
232
|
+
*/
|
|
233
|
+
stop(): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Execute a tool directly (for testing)
|
|
236
|
+
*/
|
|
237
|
+
callTool(name: string, args: unknown): Promise<unknown>;
|
|
238
|
+
/**
|
|
239
|
+
* Get the underlying MCP server instance
|
|
240
|
+
*/
|
|
241
|
+
getServer(): Server;
|
|
242
|
+
/**
|
|
243
|
+
* Get the TopGun client instance
|
|
244
|
+
*/
|
|
245
|
+
getClient(): TopGunClient;
|
|
246
|
+
/**
|
|
247
|
+
* Get resolved configuration
|
|
248
|
+
*/
|
|
249
|
+
getConfig(): ResolvedMCPServerConfig;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* HTTP/SSE Transport for MCP Server
|
|
254
|
+
*
|
|
255
|
+
* Provides HTTP-based transport for web MCP clients
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* HTTP Server configuration
|
|
260
|
+
*/
|
|
261
|
+
interface HTTPServerConfig {
|
|
262
|
+
/**
|
|
263
|
+
* Port to listen on
|
|
264
|
+
* @default 3000
|
|
265
|
+
*/
|
|
266
|
+
port?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Host to bind to
|
|
269
|
+
* @default '0.0.0.0'
|
|
270
|
+
*/
|
|
271
|
+
host?: string;
|
|
272
|
+
/**
|
|
273
|
+
* CORS allowed origins
|
|
274
|
+
* @default ['*']
|
|
275
|
+
*/
|
|
276
|
+
corsOrigins?: string[];
|
|
277
|
+
/**
|
|
278
|
+
* Path for MCP endpoint
|
|
279
|
+
* @default '/mcp'
|
|
280
|
+
*/
|
|
281
|
+
mcpPath?: string;
|
|
282
|
+
/**
|
|
283
|
+
* Path for SSE events
|
|
284
|
+
* @default '/mcp/events'
|
|
285
|
+
*/
|
|
286
|
+
eventPath?: string;
|
|
287
|
+
/**
|
|
288
|
+
* Enable debug logging
|
|
289
|
+
* @default false
|
|
290
|
+
*/
|
|
291
|
+
debug?: boolean;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* HTTP Transport wrapper for MCP Server
|
|
295
|
+
*/
|
|
296
|
+
declare class HTTPTransport {
|
|
297
|
+
private readonly config;
|
|
298
|
+
private httpServer?;
|
|
299
|
+
private isRunning;
|
|
300
|
+
private activeSessions;
|
|
301
|
+
constructor(config?: HTTPServerConfig);
|
|
302
|
+
/**
|
|
303
|
+
* Start HTTP server with MCP transport
|
|
304
|
+
*/
|
|
305
|
+
start(mcpServer: TopGunMCPServer): Promise<void>;
|
|
306
|
+
/**
|
|
307
|
+
* Stop HTTP server
|
|
308
|
+
*/
|
|
309
|
+
stop(): Promise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Handle incoming HTTP request
|
|
312
|
+
*/
|
|
313
|
+
private handleRequest;
|
|
314
|
+
/**
|
|
315
|
+
* Handle SSE connection for real-time MCP
|
|
316
|
+
*/
|
|
317
|
+
private handleSSEConnection;
|
|
318
|
+
/**
|
|
319
|
+
* Handle stateless MCP POST request
|
|
320
|
+
*/
|
|
321
|
+
private handleMCPRequest;
|
|
322
|
+
/**
|
|
323
|
+
* Read request body
|
|
324
|
+
*/
|
|
325
|
+
private readBody;
|
|
326
|
+
/**
|
|
327
|
+
* Set CORS headers
|
|
328
|
+
*/
|
|
329
|
+
private setCorsHeaders;
|
|
330
|
+
/**
|
|
331
|
+
* Debug logging
|
|
332
|
+
*/
|
|
333
|
+
private log;
|
|
334
|
+
/**
|
|
335
|
+
* Get current session count
|
|
336
|
+
*/
|
|
337
|
+
getSessionCount(): number;
|
|
338
|
+
/**
|
|
339
|
+
* Check if running
|
|
340
|
+
*/
|
|
341
|
+
isActive(): boolean;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Create and start an HTTP transport
|
|
345
|
+
*/
|
|
346
|
+
declare function createHTTPServer(mcpServer: TopGunMCPServer, config?: HTTPServerConfig): Promise<HTTPTransport>;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* topgun_query - Query data from a TopGun map with filters
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
declare const queryTool: MCPTool;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* topgun_mutate - Create, update, or delete data in a TopGun map
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
declare const mutateTool: MCPTool;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* topgun_search - Perform hybrid search (exact + full-text) across a map
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
declare const searchTool: MCPTool;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* topgun_subscribe - Watch a map for real-time changes
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
declare const subscribeTool: MCPTool;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* topgun_schema - Get schema information about a map
|
|
374
|
+
*/
|
|
375
|
+
|
|
376
|
+
declare const schemaTool: MCPTool;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* topgun_stats - Get statistics about TopGun maps
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
declare const statsTool: MCPTool;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* topgun_explain - Explain how a query would be executed
|
|
386
|
+
*/
|
|
387
|
+
|
|
388
|
+
declare const explainTool: MCPTool;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* topgun_list_maps - List all available maps
|
|
392
|
+
*/
|
|
393
|
+
|
|
394
|
+
declare const listMapsTool: MCPTool;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* MCP Tools Index
|
|
398
|
+
* Exports all tool definitions and handlers
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* All available tools
|
|
403
|
+
*/
|
|
404
|
+
declare const allTools: MCPTool[];
|
|
405
|
+
/**
|
|
406
|
+
* Tool handlers map
|
|
407
|
+
*/
|
|
408
|
+
declare const toolHandlers: Record<string, (args: unknown, ctx: ToolContext) => Promise<MCPToolResult>>;
|
|
409
|
+
|
|
410
|
+
export { type ExplainToolArgs, type HTTPServerConfig, HTTPTransport, type ListMapsToolArgs, type MCPServerConfig, type MCPTool, type MCPToolResult, type MutateToolArgs, type QueryToolArgs, type ResolvedMCPServerConfig, type SchemaToolArgs, type SearchToolArgs, type StatsToolArgs, type SubscribeToolArgs, type ToolContext, TopGunMCPServer, allTools, createHTTPServer, explainTool, listMapsTool, mutateTool, queryTool, schemaTool, searchTool, statsTool, subscribeTool, toolHandlers };
|