@codingame/monaco-vscode-mcp-service-override 16.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.
- package/index.d.ts +2 -0
- package/index.js +20 -0
- package/package.json +50 -0
- package/vscode/src/vs/platform/mcp/common/nativeMcpDiscoveryHelper.d.ts +9 -0
- package/vscode/src/vs/platform/mcp/common/nativeMcpDiscoveryHelper.js +5 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcp.contribution.d.ts +1 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcp.contribution.js +47 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpDiscovery.d.ts +8 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpDiscovery.js +36 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.d.ts +21 -0
- package/vscode/src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.js +340 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/configMcpDiscovery.d.ts +17 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/configMcpDiscovery.js +146 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/extensionMcpDiscovery.d.ts +15 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/extensionMcpDiscovery.js +108 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/mcpDiscovery.d.ts +12 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/mcpDiscovery.js +16 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAbstract.d.ts +34 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAbstract.js +134 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAdapters.d.ts +34 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAdapters.js +79 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpRemoteDiscovery.d.ts +14 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/nativeMcpRemoteDiscovery.js +44 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/workspaceMcpDiscoveryAdapter.d.ts +15 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/discovery/workspaceMcpDiscoveryAdapter.js +68 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpConfigFileUtils.d.ts +6 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpConfigFileUtils.js +30 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpConfigPathsService.d.ts +33 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpConfigPathsService.js +112 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.d.ts +59 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistry.js +322 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistryInputStorage.d.ts +27 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpRegistryInputStorage.js +134 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServer.d.ts +77 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServer.js +383 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.d.ts +26 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerConnection.js +114 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.d.ts +63 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpServerRequestHandler.js +318 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpService.d.ts +27 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/mcpService.js +220 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/modelContextProtocol.d.ts +374 -0
- package/vscode/src/vs/workbench/contrib/mcp/common/modelContextProtocol.js +14 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
|
|
2
|
+
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
+
import { RunOnceScheduler } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
|
|
4
|
+
import { Codicon } from '@codingame/monaco-vscode-api/vscode/vs/base/common/codicons';
|
|
5
|
+
import { MarkdownString } from '@codingame/monaco-vscode-api/vscode/vs/base/common/htmlContent';
|
|
6
|
+
import { Disposable, toDisposable, DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
7
|
+
import { equals } from '@codingame/monaco-vscode-api/vscode/vs/base/common/objects';
|
|
8
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
|
|
9
|
+
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
|
|
10
|
+
import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
|
|
11
|
+
import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
|
|
12
|
+
import { IProductService } from '@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service';
|
|
13
|
+
import { StorageScope } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
|
|
14
|
+
import { ILanguageModelToolsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/languageModelToolsService.service';
|
|
15
|
+
import { IMcpRegistry } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpRegistryTypes.service';
|
|
16
|
+
import { McpServerMetadataCache, McpServer } from './mcpServer.js';
|
|
17
|
+
import { McpServerToolsState, McpServerDefinition } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/mcp/common/mcpTypes';
|
|
18
|
+
import { observableValue, transaction } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/base';
|
|
19
|
+
import { autorun } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/autorun';
|
|
20
|
+
|
|
21
|
+
let McpService = class McpService extends Disposable {
|
|
22
|
+
get lazyCollectionState() { return this._mcpRegistry.lazyCollectionState; }
|
|
23
|
+
constructor(_instantiationService, _mcpRegistry, _toolsService, _logService) {
|
|
24
|
+
super();
|
|
25
|
+
this._instantiationService = _instantiationService;
|
|
26
|
+
this._mcpRegistry = _mcpRegistry;
|
|
27
|
+
this._toolsService = _toolsService;
|
|
28
|
+
this._logService = _logService;
|
|
29
|
+
this._servers = observableValue(this, []);
|
|
30
|
+
this.servers = ( this._servers.map(servers => ( servers.map(s => s.object))));
|
|
31
|
+
this.userCache = this._register(_instantiationService.createInstance(McpServerMetadataCache, StorageScope.PROFILE));
|
|
32
|
+
this.workspaceCache = this._register(_instantiationService.createInstance(McpServerMetadataCache, StorageScope.WORKSPACE));
|
|
33
|
+
const updateThrottle = this._store.add(( new RunOnceScheduler(() => this._updateCollectedServers(), 500)));
|
|
34
|
+
this._register(autorun(reader => {
|
|
35
|
+
for (const collection of this._mcpRegistry.collections.read(reader)) {
|
|
36
|
+
collection.serverDefinitions.read(reader);
|
|
37
|
+
}
|
|
38
|
+
updateThrottle.schedule(500);
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
resetCaches() {
|
|
42
|
+
this.userCache.reset();
|
|
43
|
+
this.workspaceCache.reset();
|
|
44
|
+
}
|
|
45
|
+
async activateCollections() {
|
|
46
|
+
const collections = await this._mcpRegistry.discoverCollections();
|
|
47
|
+
const collectionIds = ( new Set(( collections.map(c => c.id))));
|
|
48
|
+
this._updateCollectedServers();
|
|
49
|
+
const todo = [];
|
|
50
|
+
for (const { object: server } of this._servers.get()) {
|
|
51
|
+
if (( collectionIds.has(server.collection.id))) {
|
|
52
|
+
const state = server.toolsState.get();
|
|
53
|
+
if (state === McpServerToolsState.Unknown) {
|
|
54
|
+
todo.push(server.start());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await Promise.all(todo);
|
|
59
|
+
}
|
|
60
|
+
_syncTools(server, store) {
|
|
61
|
+
const tools = ( new Map());
|
|
62
|
+
store.add(autorun(reader => {
|
|
63
|
+
const toDelete = ( new Set(( tools.keys())));
|
|
64
|
+
for (const tool of server.tools.read(reader)) {
|
|
65
|
+
const existing = tools.get(tool.id);
|
|
66
|
+
const collection = this._mcpRegistry.collections.get().find(c => c.id === server.collection.id);
|
|
67
|
+
const toolData = {
|
|
68
|
+
id: tool.id,
|
|
69
|
+
source: { type: 'mcp', collectionId: server.collection.id, definitionId: server.definition.id },
|
|
70
|
+
icon: Codicon.tools,
|
|
71
|
+
displayName: tool.definition.name,
|
|
72
|
+
toolReferenceName: tool.definition.name,
|
|
73
|
+
modelDescription: tool.definition.description ?? '',
|
|
74
|
+
userDescription: tool.definition.description ?? '',
|
|
75
|
+
inputSchema: tool.definition.inputSchema,
|
|
76
|
+
canBeReferencedInPrompt: true,
|
|
77
|
+
supportsToolPicker: true,
|
|
78
|
+
runsInWorkspace: collection?.scope === StorageScope.WORKSPACE || !!collection?.remoteAuthority,
|
|
79
|
+
tags: ['mcp'],
|
|
80
|
+
};
|
|
81
|
+
if (existing) {
|
|
82
|
+
if (!equals(existing.toolData, toolData)) {
|
|
83
|
+
existing.toolData = toolData;
|
|
84
|
+
existing.toolDispose.dispose();
|
|
85
|
+
existing.toolDispose = this._toolsService.registerToolData(toolData);
|
|
86
|
+
}
|
|
87
|
+
toDelete.delete(tool.id);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
tools.set(tool.id, {
|
|
91
|
+
toolData,
|
|
92
|
+
toolDispose: this._toolsService.registerToolData(toolData),
|
|
93
|
+
implDispose: this._toolsService.registerToolImplementation(tool.id, this._instantiationService.createInstance(McpToolImplementation, tool, server)),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const id of toDelete) {
|
|
98
|
+
const tool = tools.get(id);
|
|
99
|
+
if (tool) {
|
|
100
|
+
tool.toolDispose.dispose();
|
|
101
|
+
tool.implDispose.dispose();
|
|
102
|
+
tools.delete(id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
store.add(toDisposable(() => {
|
|
107
|
+
for (const tool of ( tools.values())) {
|
|
108
|
+
tool.toolDispose.dispose();
|
|
109
|
+
tool.implDispose.dispose();
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
_updateCollectedServers() {
|
|
114
|
+
const definitions = this._mcpRegistry.collections.get().flatMap(collectionDefinition => ( collectionDefinition.serverDefinitions.get().map(serverDefinition => ({
|
|
115
|
+
serverDefinition,
|
|
116
|
+
collectionDefinition,
|
|
117
|
+
}))));
|
|
118
|
+
const nextDefinitions = ( new Set(definitions));
|
|
119
|
+
const currentServers = this._servers.get();
|
|
120
|
+
const nextServers = [];
|
|
121
|
+
const pushMatch = (match, rec) => {
|
|
122
|
+
nextDefinitions.delete(match);
|
|
123
|
+
nextServers.push(rec);
|
|
124
|
+
const connection = rec.object.connection.get();
|
|
125
|
+
if (connection && !McpServerDefinition.equals(connection.definition, match.serverDefinition)) {
|
|
126
|
+
rec.object.stop();
|
|
127
|
+
this._logService.debug(`MCP server ${rec.object.definition.id} stopped because the definition changed`);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
for (const server of currentServers) {
|
|
131
|
+
const match = definitions.find(d => defsEqual(server.object, d));
|
|
132
|
+
if (match) {
|
|
133
|
+
pushMatch(match, server);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
server.dispose();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const def of nextDefinitions) {
|
|
140
|
+
const store = ( new DisposableStore());
|
|
141
|
+
const object = this._instantiationService.createInstance(McpServer, def.collectionDefinition, def.serverDefinition, def.serverDefinition.roots, !!def.collectionDefinition.lazy, def.collectionDefinition.scope === StorageScope.WORKSPACE ? this.workspaceCache : this.userCache);
|
|
142
|
+
store.add(object);
|
|
143
|
+
this._syncTools(object, store);
|
|
144
|
+
nextServers.push({ object, dispose: () => store.dispose() });
|
|
145
|
+
}
|
|
146
|
+
transaction(tx => {
|
|
147
|
+
this._servers.set(nextServers, tx);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
dispose() {
|
|
151
|
+
this._servers.get().forEach(s => s.dispose());
|
|
152
|
+
super.dispose();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
McpService = ( __decorate([
|
|
156
|
+
( __param(0, IInstantiationService)),
|
|
157
|
+
( __param(1, IMcpRegistry)),
|
|
158
|
+
( __param(2, ILanguageModelToolsService)),
|
|
159
|
+
( __param(3, ILogService))
|
|
160
|
+
], McpService));
|
|
161
|
+
function defsEqual(server, def) {
|
|
162
|
+
return server.collection.id === def.collectionDefinition.id && server.definition.id === def.serverDefinition.id;
|
|
163
|
+
}
|
|
164
|
+
let McpToolImplementation = class McpToolImplementation {
|
|
165
|
+
constructor(_tool, _server, _productService) {
|
|
166
|
+
this._tool = _tool;
|
|
167
|
+
this._server = _server;
|
|
168
|
+
this._productService = _productService;
|
|
169
|
+
}
|
|
170
|
+
async prepareToolInvocation(parameters) {
|
|
171
|
+
const tool = this._tool;
|
|
172
|
+
const server = this._server;
|
|
173
|
+
const mcpToolWarning = ( localize(
|
|
174
|
+
7667,
|
|
175
|
+
"{0} This tool is from \'{1}\' (MCP Server). Note that MCP servers or malicious conversation content may attempt to misuse '{2}' through tools. Please carefully review any requested actions.",
|
|
176
|
+
'$(info)',
|
|
177
|
+
server.definition.label,
|
|
178
|
+
this._productService.nameShort
|
|
179
|
+
));
|
|
180
|
+
return {
|
|
181
|
+
confirmationMessages: {
|
|
182
|
+
title: ( localize(7668, "Run `{0}`", tool.definition.name, server.definition.label)),
|
|
183
|
+
message: ( new MarkdownString(( localize(7669, "{0}\n\n {1}", tool.definition.description, mcpToolWarning)), { supportThemeIcons: true })),
|
|
184
|
+
allowAutoConfirm: true,
|
|
185
|
+
},
|
|
186
|
+
invocationMessage: ( new MarkdownString(( localize(7670, "Running `{0}`", tool.definition.name, server.definition.label)))),
|
|
187
|
+
pastTenseMessage: ( new MarkdownString(( localize(7671, "Ran `{0}` ", tool.definition.name, server.definition.label)))),
|
|
188
|
+
toolSpecificData: {
|
|
189
|
+
kind: 'input',
|
|
190
|
+
rawInput: parameters
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
async invoke(invocation, _countTokens, token) {
|
|
195
|
+
const result = {
|
|
196
|
+
content: []
|
|
197
|
+
};
|
|
198
|
+
const outputParts = [];
|
|
199
|
+
const callResult = await this._tool.call(invocation.parameters, token);
|
|
200
|
+
for (const item of callResult.content) {
|
|
201
|
+
if (item.type === 'text') {
|
|
202
|
+
result.content.push({
|
|
203
|
+
kind: 'text',
|
|
204
|
+
value: item.text
|
|
205
|
+
});
|
|
206
|
+
outputParts.push(item.text);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
result.toolResultDetails = {
|
|
210
|
+
input: JSON.stringify(invocation.parameters, undefined, 2),
|
|
211
|
+
output: outputParts.join('\n')
|
|
212
|
+
};
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
McpToolImplementation = ( __decorate([
|
|
217
|
+
( __param(2, IProductService))
|
|
218
|
+
], McpToolImplementation));
|
|
219
|
+
|
|
220
|
+
export { McpService };
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
export declare namespace MCP {
|
|
2
|
+
type JSONRPCMessage = JSONRPCRequest | JSONRPCNotification | JSONRPCResponse | JSONRPCError;
|
|
3
|
+
const LATEST_PROTOCOL_VERSION = "2024-11-05";
|
|
4
|
+
const JSONRPC_VERSION = "2.0";
|
|
5
|
+
type ProgressToken = string | number;
|
|
6
|
+
type Cursor = string;
|
|
7
|
+
interface Request {
|
|
8
|
+
method: string;
|
|
9
|
+
params?: {
|
|
10
|
+
_meta?: {
|
|
11
|
+
progressToken?: ProgressToken;
|
|
12
|
+
};
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface Notification {
|
|
17
|
+
method: string;
|
|
18
|
+
params?: {
|
|
19
|
+
_meta?: {
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface Result {
|
|
26
|
+
_meta?: {
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
type RequestId = string | number;
|
|
32
|
+
interface JSONRPCRequest extends Request {
|
|
33
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
34
|
+
id: RequestId;
|
|
35
|
+
}
|
|
36
|
+
interface JSONRPCNotification extends Notification {
|
|
37
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
38
|
+
}
|
|
39
|
+
interface JSONRPCResponse {
|
|
40
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
41
|
+
id: RequestId;
|
|
42
|
+
result: Result;
|
|
43
|
+
}
|
|
44
|
+
const PARSE_ERROR = -32700;
|
|
45
|
+
const INVALID_REQUEST = -32600;
|
|
46
|
+
const METHOD_NOT_FOUND = -32601;
|
|
47
|
+
const INVALID_PARAMS = -32602;
|
|
48
|
+
const INTERNAL_ERROR = -32603;
|
|
49
|
+
interface JSONRPCError {
|
|
50
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
51
|
+
id: RequestId;
|
|
52
|
+
error: {
|
|
53
|
+
code: number;
|
|
54
|
+
message: string;
|
|
55
|
+
data?: unknown;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
type EmptyResult = Result;
|
|
59
|
+
interface CancelledNotification extends Notification {
|
|
60
|
+
method: "notifications/cancelled";
|
|
61
|
+
params: {
|
|
62
|
+
requestId: RequestId;
|
|
63
|
+
reason?: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
interface InitializeRequest extends Request {
|
|
67
|
+
method: "initialize";
|
|
68
|
+
params: {
|
|
69
|
+
protocolVersion: string;
|
|
70
|
+
capabilities: ClientCapabilities;
|
|
71
|
+
clientInfo: Implementation;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
interface InitializeResult extends Result {
|
|
75
|
+
protocolVersion: string;
|
|
76
|
+
capabilities: ServerCapabilities;
|
|
77
|
+
serverInfo: Implementation;
|
|
78
|
+
instructions?: string;
|
|
79
|
+
}
|
|
80
|
+
interface InitializedNotification extends Notification {
|
|
81
|
+
method: "notifications/initialized";
|
|
82
|
+
}
|
|
83
|
+
interface ClientCapabilities {
|
|
84
|
+
experimental?: {
|
|
85
|
+
[key: string]: object;
|
|
86
|
+
};
|
|
87
|
+
roots?: {
|
|
88
|
+
listChanged?: boolean;
|
|
89
|
+
};
|
|
90
|
+
sampling?: object;
|
|
91
|
+
}
|
|
92
|
+
interface ServerCapabilities {
|
|
93
|
+
experimental?: {
|
|
94
|
+
[key: string]: object;
|
|
95
|
+
};
|
|
96
|
+
logging?: object;
|
|
97
|
+
prompts?: {
|
|
98
|
+
listChanged?: boolean;
|
|
99
|
+
};
|
|
100
|
+
resources?: {
|
|
101
|
+
subscribe?: boolean;
|
|
102
|
+
listChanged?: boolean;
|
|
103
|
+
};
|
|
104
|
+
tools?: {
|
|
105
|
+
listChanged?: boolean;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
interface Implementation {
|
|
109
|
+
name: string;
|
|
110
|
+
version: string;
|
|
111
|
+
}
|
|
112
|
+
interface PingRequest extends Request {
|
|
113
|
+
method: "ping";
|
|
114
|
+
}
|
|
115
|
+
interface ProgressNotification extends Notification {
|
|
116
|
+
method: "notifications/progress";
|
|
117
|
+
params: {
|
|
118
|
+
progressToken: ProgressToken;
|
|
119
|
+
progress: number;
|
|
120
|
+
total?: number;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
interface PaginatedRequest extends Request {
|
|
124
|
+
params?: {
|
|
125
|
+
cursor?: Cursor;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
interface PaginatedResult extends Result {
|
|
129
|
+
nextCursor?: Cursor;
|
|
130
|
+
}
|
|
131
|
+
interface ListResourcesRequest extends PaginatedRequest {
|
|
132
|
+
method: "resources/list";
|
|
133
|
+
}
|
|
134
|
+
interface ListResourcesResult extends PaginatedResult {
|
|
135
|
+
resources: Resource[];
|
|
136
|
+
}
|
|
137
|
+
interface ListResourceTemplatesRequest extends PaginatedRequest {
|
|
138
|
+
method: "resources/templates/list";
|
|
139
|
+
}
|
|
140
|
+
interface ListResourceTemplatesResult extends PaginatedResult {
|
|
141
|
+
resourceTemplates: ResourceTemplate[];
|
|
142
|
+
}
|
|
143
|
+
interface ReadResourceRequest extends Request {
|
|
144
|
+
method: "resources/read";
|
|
145
|
+
params: {
|
|
146
|
+
uri: string;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
interface ReadResourceResult extends Result {
|
|
150
|
+
contents: (TextResourceContents | BlobResourceContents)[];
|
|
151
|
+
}
|
|
152
|
+
interface ResourceListChangedNotification extends Notification {
|
|
153
|
+
method: "notifications/resources/list_changed";
|
|
154
|
+
}
|
|
155
|
+
interface SubscribeRequest extends Request {
|
|
156
|
+
method: "resources/subscribe";
|
|
157
|
+
params: {
|
|
158
|
+
uri: string;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
interface UnsubscribeRequest extends Request {
|
|
162
|
+
method: "resources/unsubscribe";
|
|
163
|
+
params: {
|
|
164
|
+
uri: string;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
interface ResourceUpdatedNotification extends Notification {
|
|
168
|
+
method: "notifications/resources/updated";
|
|
169
|
+
params: {
|
|
170
|
+
uri: string;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
interface Resource extends Annotated {
|
|
174
|
+
uri: string;
|
|
175
|
+
name: string;
|
|
176
|
+
description?: string;
|
|
177
|
+
mimeType?: string;
|
|
178
|
+
size?: number;
|
|
179
|
+
}
|
|
180
|
+
interface ResourceTemplate extends Annotated {
|
|
181
|
+
uriTemplate: string;
|
|
182
|
+
name: string;
|
|
183
|
+
description?: string;
|
|
184
|
+
mimeType?: string;
|
|
185
|
+
}
|
|
186
|
+
interface ResourceContents {
|
|
187
|
+
uri: string;
|
|
188
|
+
mimeType?: string;
|
|
189
|
+
}
|
|
190
|
+
interface TextResourceContents extends ResourceContents {
|
|
191
|
+
text: string;
|
|
192
|
+
}
|
|
193
|
+
interface BlobResourceContents extends ResourceContents {
|
|
194
|
+
blob: string;
|
|
195
|
+
}
|
|
196
|
+
interface ListPromptsRequest extends PaginatedRequest {
|
|
197
|
+
method: "prompts/list";
|
|
198
|
+
}
|
|
199
|
+
interface ListPromptsResult extends PaginatedResult {
|
|
200
|
+
prompts: Prompt[];
|
|
201
|
+
}
|
|
202
|
+
interface GetPromptRequest extends Request {
|
|
203
|
+
method: "prompts/get";
|
|
204
|
+
params: {
|
|
205
|
+
name: string;
|
|
206
|
+
arguments?: {
|
|
207
|
+
[key: string]: string;
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
interface GetPromptResult extends Result {
|
|
212
|
+
description?: string;
|
|
213
|
+
messages: PromptMessage[];
|
|
214
|
+
}
|
|
215
|
+
interface Prompt {
|
|
216
|
+
name: string;
|
|
217
|
+
description?: string;
|
|
218
|
+
arguments?: PromptArgument[];
|
|
219
|
+
}
|
|
220
|
+
interface PromptArgument {
|
|
221
|
+
name: string;
|
|
222
|
+
description?: string;
|
|
223
|
+
required?: boolean;
|
|
224
|
+
}
|
|
225
|
+
type Role = "user" | "assistant";
|
|
226
|
+
interface PromptMessage {
|
|
227
|
+
role: Role;
|
|
228
|
+
content: TextContent | ImageContent | EmbeddedResource;
|
|
229
|
+
}
|
|
230
|
+
interface EmbeddedResource extends Annotated {
|
|
231
|
+
type: "resource";
|
|
232
|
+
resource: TextResourceContents | BlobResourceContents;
|
|
233
|
+
}
|
|
234
|
+
interface PromptListChangedNotification extends Notification {
|
|
235
|
+
method: "notifications/prompts/list_changed";
|
|
236
|
+
}
|
|
237
|
+
interface ListToolsRequest extends PaginatedRequest {
|
|
238
|
+
method: "tools/list";
|
|
239
|
+
}
|
|
240
|
+
interface ListToolsResult extends PaginatedResult {
|
|
241
|
+
tools: Tool[];
|
|
242
|
+
}
|
|
243
|
+
interface CallToolResult extends Result {
|
|
244
|
+
content: (TextContent | ImageContent | EmbeddedResource)[];
|
|
245
|
+
isError?: boolean;
|
|
246
|
+
}
|
|
247
|
+
interface CallToolRequest extends Request {
|
|
248
|
+
method: "tools/call";
|
|
249
|
+
params: {
|
|
250
|
+
name: string;
|
|
251
|
+
arguments?: {
|
|
252
|
+
[key: string]: unknown;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
interface ToolListChangedNotification extends Notification {
|
|
257
|
+
method: "notifications/tools/list_changed";
|
|
258
|
+
}
|
|
259
|
+
interface Tool {
|
|
260
|
+
name: string;
|
|
261
|
+
description?: string;
|
|
262
|
+
inputSchema: {
|
|
263
|
+
type: "object";
|
|
264
|
+
properties?: {
|
|
265
|
+
[key: string]: object;
|
|
266
|
+
};
|
|
267
|
+
required?: string[];
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
interface SetLevelRequest extends Request {
|
|
271
|
+
method: "logging/setLevel";
|
|
272
|
+
params: {
|
|
273
|
+
level: LoggingLevel;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
interface LoggingMessageNotification extends Notification {
|
|
277
|
+
method: "notifications/message";
|
|
278
|
+
params: {
|
|
279
|
+
level: LoggingLevel;
|
|
280
|
+
logger?: string;
|
|
281
|
+
data: unknown;
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
type LoggingLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency";
|
|
285
|
+
interface CreateMessageRequest extends Request {
|
|
286
|
+
method: "sampling/createMessage";
|
|
287
|
+
params: {
|
|
288
|
+
messages: SamplingMessage[];
|
|
289
|
+
modelPreferences?: ModelPreferences;
|
|
290
|
+
systemPrompt?: string;
|
|
291
|
+
includeContext?: "none" | "thisServer" | "allServers";
|
|
292
|
+
temperature?: number;
|
|
293
|
+
maxTokens: number;
|
|
294
|
+
stopSequences?: string[];
|
|
295
|
+
metadata?: object;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
interface CreateMessageResult extends Result, SamplingMessage {
|
|
299
|
+
model: string;
|
|
300
|
+
stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
|
|
301
|
+
}
|
|
302
|
+
interface SamplingMessage {
|
|
303
|
+
role: Role;
|
|
304
|
+
content: TextContent | ImageContent;
|
|
305
|
+
}
|
|
306
|
+
interface Annotated {
|
|
307
|
+
annotations?: {
|
|
308
|
+
audience?: Role[];
|
|
309
|
+
priority?: number;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
interface TextContent extends Annotated {
|
|
313
|
+
type: "text";
|
|
314
|
+
text: string;
|
|
315
|
+
}
|
|
316
|
+
interface ImageContent extends Annotated {
|
|
317
|
+
type: "image";
|
|
318
|
+
data: string;
|
|
319
|
+
mimeType: string;
|
|
320
|
+
}
|
|
321
|
+
interface ModelPreferences {
|
|
322
|
+
hints?: ModelHint[];
|
|
323
|
+
costPriority?: number;
|
|
324
|
+
speedPriority?: number;
|
|
325
|
+
intelligencePriority?: number;
|
|
326
|
+
}
|
|
327
|
+
interface ModelHint {
|
|
328
|
+
name?: string;
|
|
329
|
+
}
|
|
330
|
+
interface CompleteRequest extends Request {
|
|
331
|
+
method: "completion/complete";
|
|
332
|
+
params: {
|
|
333
|
+
ref: PromptReference | ResourceReference;
|
|
334
|
+
argument: {
|
|
335
|
+
name: string;
|
|
336
|
+
value: string;
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
interface CompleteResult extends Result {
|
|
341
|
+
completion: {
|
|
342
|
+
values: string[];
|
|
343
|
+
total?: number;
|
|
344
|
+
hasMore?: boolean;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
interface ResourceReference {
|
|
348
|
+
type: "ref/resource";
|
|
349
|
+
uri: string;
|
|
350
|
+
}
|
|
351
|
+
interface PromptReference {
|
|
352
|
+
type: "ref/prompt";
|
|
353
|
+
name: string;
|
|
354
|
+
}
|
|
355
|
+
interface ListRootsRequest extends Request {
|
|
356
|
+
method: "roots/list";
|
|
357
|
+
}
|
|
358
|
+
interface ListRootsResult extends Result {
|
|
359
|
+
roots: Root[];
|
|
360
|
+
}
|
|
361
|
+
interface Root {
|
|
362
|
+
uri: string;
|
|
363
|
+
name?: string;
|
|
364
|
+
}
|
|
365
|
+
interface RootsListChangedNotification extends Notification {
|
|
366
|
+
method: "notifications/roots/list_changed";
|
|
367
|
+
}
|
|
368
|
+
type ClientRequest = PingRequest | InitializeRequest | CompleteRequest | SetLevelRequest | GetPromptRequest | ListPromptsRequest | ListResourcesRequest | ListResourceTemplatesRequest | ReadResourceRequest | SubscribeRequest | UnsubscribeRequest | CallToolRequest | ListToolsRequest;
|
|
369
|
+
type ClientNotification = CancelledNotification | ProgressNotification | InitializedNotification | RootsListChangedNotification;
|
|
370
|
+
type ClientResult = EmptyResult | CreateMessageResult | ListRootsResult;
|
|
371
|
+
type ServerRequest = PingRequest | CreateMessageRequest | ListRootsRequest;
|
|
372
|
+
type ServerNotification = CancelledNotification | ProgressNotification | LoggingMessageNotification | ResourceUpdatedNotification | ResourceListChangedNotification | ToolListChangedNotification | PromptListChangedNotification;
|
|
373
|
+
type ServerResult = EmptyResult | InitializeResult | CompleteResult | GetPromptResult | ListPromptsResult | ListResourcesResult | ListResourceTemplatesResult | ReadResourceResult | CallToolResult | ListToolsResult;
|
|
374
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
var MCP;
|
|
4
|
+
(function (MCP) {
|
|
5
|
+
MCP.LATEST_PROTOCOL_VERSION = "2024-11-05";
|
|
6
|
+
MCP.JSONRPC_VERSION = "2.0";
|
|
7
|
+
MCP.PARSE_ERROR = -32700;
|
|
8
|
+
MCP.INVALID_REQUEST = -32600;
|
|
9
|
+
MCP.METHOD_NOT_FOUND = -32601;
|
|
10
|
+
MCP.INVALID_PARAMS = -32602;
|
|
11
|
+
MCP.INTERNAL_ERROR = -32603;
|
|
12
|
+
})(MCP || (MCP = {}));
|
|
13
|
+
|
|
14
|
+
export { MCP };
|