@llamaindex/llama-cloud-mcp 1.5.0 → 1.7.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/auth.d.mts +6 -0
- package/auth.d.mts.map +1 -0
- package/auth.d.ts +6 -0
- package/auth.d.ts.map +1 -0
- package/{headers.mjs → auth.js} +18 -2
- package/auth.js.map +1 -0
- package/{headers.js → auth.mjs} +13 -6
- package/auth.mjs.map +1 -0
- package/code-tool-paths.cjs +6 -0
- package/code-tool-paths.cjs.map +1 -0
- package/code-tool-paths.d.cts +2 -0
- package/code-tool-paths.d.cts.map +1 -0
- package/code-tool-types.d.mts.map +1 -1
- package/code-tool-types.d.ts.map +1 -1
- package/code-tool-worker.d.mts +5 -0
- package/code-tool-worker.d.mts.map +1 -0
- package/code-tool-worker.d.ts +5 -0
- package/code-tool-worker.d.ts.map +1 -0
- package/code-tool-worker.js +345 -0
- package/code-tool-worker.js.map +1 -0
- package/code-tool-worker.mjs +340 -0
- package/code-tool-worker.mjs.map +1 -0
- package/code-tool.d.mts +8 -2
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +8 -2
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +264 -42
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +229 -43
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +9 -3
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +9 -3
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +27 -4
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +27 -4
- package/docs-search-tool.mjs.map +1 -1
- package/http.d.mts +3 -5
- package/http.d.mts.map +1 -1
- package/http.d.ts +3 -5
- package/http.d.ts.map +1 -1
- package/http.js +66 -43
- package/http.js.map +1 -1
- package/http.mjs +66 -43
- package/http.mjs.map +1 -1
- package/index.js +13 -12
- package/index.js.map +1 -1
- package/index.mjs +13 -12
- package/index.mjs.map +1 -1
- package/instructions.d.mts +2 -0
- package/instructions.d.mts.map +1 -0
- package/instructions.d.ts +2 -0
- package/instructions.d.ts.map +1 -0
- package/instructions.js +56 -0
- package/instructions.js.map +1 -0
- package/instructions.mjs +53 -0
- package/instructions.mjs.map +1 -0
- package/logger.d.mts +7 -0
- package/logger.d.mts.map +1 -0
- package/logger.d.ts +7 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +29 -0
- package/logger.js.map +1 -0
- package/logger.mjs +22 -0
- package/logger.mjs.map +1 -0
- package/methods.d.mts.map +1 -1
- package/methods.d.ts.map +1 -1
- package/methods.js +1 -0
- package/methods.js.map +1 -1
- package/methods.mjs +1 -0
- package/methods.mjs.map +1 -1
- package/options.d.mts +5 -0
- package/options.d.mts.map +1 -1
- package/options.d.ts +5 -0
- package/options.d.ts.map +1 -1
- package/options.js +31 -0
- package/options.js.map +1 -1
- package/options.mjs +31 -0
- package/options.mjs.map +1 -1
- package/package.json +62 -15
- package/server.d.mts +8 -9
- package/server.d.mts.map +1 -1
- package/server.d.ts +8 -9
- package/server.d.ts.map +1 -1
- package/server.js +73 -75
- package/server.js.map +1 -1
- package/server.mjs +72 -71
- package/server.mjs.map +1 -1
- package/src/{headers.ts → auth.ts} +16 -1
- package/src/code-tool-paths.cts +3 -0
- package/src/code-tool-types.ts +1 -0
- package/src/code-tool-worker.ts +391 -0
- package/src/code-tool.ts +309 -56
- package/src/docs-search-tool.ts +46 -6
- package/src/http.ts +74 -45
- package/src/index.ts +15 -13
- package/src/instructions.ts +75 -0
- package/src/logger.ts +28 -0
- package/src/methods.ts +2 -0
- package/src/options.ts +43 -0
- package/src/server.ts +85 -92
- package/src/stdio.ts +4 -3
- package/src/types.ts +12 -4
- package/src/util.ts +25 -0
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts.map +1 -1
- package/stdio.js +4 -3
- package/stdio.js.map +1 -1
- package/stdio.mjs +4 -3
- package/stdio.mjs.map +1 -1
- package/types.d.mts +8 -1
- package/types.d.mts.map +1 -1
- package/types.d.ts +8 -1
- package/types.d.ts.map +1 -1
- package/types.js.map +1 -1
- package/types.mjs.map +1 -1
- package/util.d.mts +4 -0
- package/util.d.mts.map +1 -0
- package/util.d.ts +4 -0
- package/util.d.ts.map +1 -0
- package/util.js +30 -0
- package/util.js.map +1 -0
- package/util.mjs +24 -0
- package/util.mjs.map +1 -0
- package/headers.d.mts +0 -4
- package/headers.d.mts.map +0 -1
- package/headers.d.ts +0 -4
- package/headers.d.ts.map +0 -1
- package/headers.js.map +0 -1
- package/headers.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llamaindex/llama-cloud-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "The official MCP Server for the Llama Cloud API",
|
|
5
5
|
"author": "Llama Cloud <>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -27,17 +27,18 @@
|
|
|
27
27
|
"fix": "eslint --fix --ext ts,js ."
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@llamaindex/llama-cloud": "^1.
|
|
30
|
+
"@llamaindex/llama-cloud": "^1.7.0",
|
|
31
31
|
"@cloudflare/cabidela": "^0.2.4",
|
|
32
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
32
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
33
33
|
"@valtown/deno-http-worker": "^0.0.21",
|
|
34
34
|
"cookie-parser": "^1.4.6",
|
|
35
35
|
"cors": "^2.8.5",
|
|
36
36
|
"express": "^5.1.0",
|
|
37
37
|
"fuse.js": "^7.1.0",
|
|
38
38
|
"jq-web": "https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"pino": "^10.3.1",
|
|
40
|
+
"pino-http": "^11.0.0",
|
|
41
|
+
"pino-pretty": "^13.1.3",
|
|
41
42
|
"qs": "^6.14.1",
|
|
42
43
|
"typescript": "5.8.3",
|
|
43
44
|
"yargs": "^17.7.2",
|
|
@@ -61,6 +62,22 @@
|
|
|
61
62
|
"types": "./index.d.mts",
|
|
62
63
|
"default": "./index.mjs"
|
|
63
64
|
},
|
|
65
|
+
"./auth": {
|
|
66
|
+
"import": "./auth.mjs",
|
|
67
|
+
"require": "./auth.js"
|
|
68
|
+
},
|
|
69
|
+
"./auth.js": {
|
|
70
|
+
"default": "./auth.js"
|
|
71
|
+
},
|
|
72
|
+
"./auth.mjs": {
|
|
73
|
+
"default": "./auth.mjs"
|
|
74
|
+
},
|
|
75
|
+
"./code-tool-paths": {
|
|
76
|
+
"require": "./code-tool-paths.cjs"
|
|
77
|
+
},
|
|
78
|
+
"./code-tool-paths.cjs": {
|
|
79
|
+
"default": "./code-tool-paths.cjs"
|
|
80
|
+
},
|
|
64
81
|
"./code-tool-types": {
|
|
65
82
|
"import": "./code-tool-types.mjs",
|
|
66
83
|
"require": "./code-tool-types.js"
|
|
@@ -71,6 +88,16 @@
|
|
|
71
88
|
"./code-tool-types.mjs": {
|
|
72
89
|
"default": "./code-tool-types.mjs"
|
|
73
90
|
},
|
|
91
|
+
"./code-tool-worker": {
|
|
92
|
+
"import": "./code-tool-worker.mjs",
|
|
93
|
+
"require": "./code-tool-worker.js"
|
|
94
|
+
},
|
|
95
|
+
"./code-tool-worker.js": {
|
|
96
|
+
"default": "./code-tool-worker.js"
|
|
97
|
+
},
|
|
98
|
+
"./code-tool-worker.mjs": {
|
|
99
|
+
"default": "./code-tool-worker.mjs"
|
|
100
|
+
},
|
|
74
101
|
"./code-tool": {
|
|
75
102
|
"import": "./code-tool.mjs",
|
|
76
103
|
"require": "./code-tool.js"
|
|
@@ -91,16 +118,6 @@
|
|
|
91
118
|
"./docs-search-tool.mjs": {
|
|
92
119
|
"default": "./docs-search-tool.mjs"
|
|
93
120
|
},
|
|
94
|
-
"./headers": {
|
|
95
|
-
"import": "./headers.mjs",
|
|
96
|
-
"require": "./headers.js"
|
|
97
|
-
},
|
|
98
|
-
"./headers.js": {
|
|
99
|
-
"default": "./headers.js"
|
|
100
|
-
},
|
|
101
|
-
"./headers.mjs": {
|
|
102
|
-
"default": "./headers.mjs"
|
|
103
|
-
},
|
|
104
121
|
"./http": {
|
|
105
122
|
"import": "./http.mjs",
|
|
106
123
|
"require": "./http.js"
|
|
@@ -121,6 +138,26 @@
|
|
|
121
138
|
"./index.mjs": {
|
|
122
139
|
"default": "./index.mjs"
|
|
123
140
|
},
|
|
141
|
+
"./instructions": {
|
|
142
|
+
"import": "./instructions.mjs",
|
|
143
|
+
"require": "./instructions.js"
|
|
144
|
+
},
|
|
145
|
+
"./instructions.js": {
|
|
146
|
+
"default": "./instructions.js"
|
|
147
|
+
},
|
|
148
|
+
"./instructions.mjs": {
|
|
149
|
+
"default": "./instructions.mjs"
|
|
150
|
+
},
|
|
151
|
+
"./logger": {
|
|
152
|
+
"import": "./logger.mjs",
|
|
153
|
+
"require": "./logger.js"
|
|
154
|
+
},
|
|
155
|
+
"./logger.js": {
|
|
156
|
+
"default": "./logger.js"
|
|
157
|
+
},
|
|
158
|
+
"./logger.mjs": {
|
|
159
|
+
"default": "./logger.mjs"
|
|
160
|
+
},
|
|
124
161
|
"./methods": {
|
|
125
162
|
"import": "./methods.mjs",
|
|
126
163
|
"require": "./methods.js"
|
|
@@ -170,6 +207,16 @@
|
|
|
170
207
|
},
|
|
171
208
|
"./types.mjs": {
|
|
172
209
|
"default": "./types.mjs"
|
|
210
|
+
},
|
|
211
|
+
"./util": {
|
|
212
|
+
"import": "./util.mjs",
|
|
213
|
+
"require": "./util.js"
|
|
214
|
+
},
|
|
215
|
+
"./util.js": {
|
|
216
|
+
"default": "./util.js"
|
|
217
|
+
},
|
|
218
|
+
"./util.mjs": {
|
|
219
|
+
"default": "./util.mjs"
|
|
173
220
|
}
|
|
174
221
|
}
|
|
175
222
|
}
|
package/server.d.mts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { ClientOptions } from '@llamaindex/llama-cloud';
|
|
4
|
-
import LlamaCloud from '@llamaindex/llama-cloud';
|
|
5
4
|
import { McpOptions } from "./options.mjs";
|
|
6
|
-
import { HandlerFunction, McpTool } from "./types.mjs";
|
|
7
|
-
export
|
|
8
|
-
export { ClientOptions } from '@llamaindex/llama-cloud';
|
|
9
|
-
export declare const newMcpServer: () => Promise<McpServer>;
|
|
5
|
+
import { HandlerFunction, McpRequestContext, ToolCallResult, McpTool } from "./types.mjs";
|
|
6
|
+
export declare const newMcpServer: (stainlessApiKey: string | undefined) => Promise<McpServer>;
|
|
10
7
|
/**
|
|
11
8
|
* Initializes the provided MCP Server with the given tools and handlers.
|
|
12
9
|
* If not provided, the default client, tools and handlers will be used.
|
|
@@ -15,6 +12,7 @@ export declare function initMcpServer(params: {
|
|
|
15
12
|
server: Server | McpServer;
|
|
16
13
|
clientOptions?: ClientOptions;
|
|
17
14
|
mcpOptions?: McpOptions;
|
|
15
|
+
stainlessApiKey?: string | undefined;
|
|
18
16
|
}): Promise<void>;
|
|
19
17
|
/**
|
|
20
18
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
@@ -23,8 +21,9 @@ export declare function selectTools(options?: McpOptions): McpTool[];
|
|
|
23
21
|
/**
|
|
24
22
|
* Runs the provided handler with the given client and arguments.
|
|
25
23
|
*/
|
|
26
|
-
export declare function executeHandler(handler
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
export declare function executeHandler({ handler, reqContext, args, }: {
|
|
25
|
+
handler: HandlerFunction;
|
|
26
|
+
reqContext: McpRequestContext;
|
|
27
|
+
args: Record<string, unknown> | undefined;
|
|
28
|
+
}): Promise<ToolCallResult>;
|
|
30
29
|
//# sourceMappingURL=server.d.mts.map
|
package/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,yBAAyB;
|
|
1
|
+
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,yBAAyB;OAKhD,EAAE,UAAU,EAAE;OAEd,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE;AAEtE,eAAO,MAAM,YAAY,GAAU,iBAAiB,MAAM,GAAG,SAAS,uBAUnE,CAAC;AAEJ;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC,iBAiHA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAe3D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GACL,EAAE;IACD,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,cAAc,CAAC,CAE1B"}
|
package/server.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { ClientOptions } from '@llamaindex/llama-cloud';
|
|
4
|
-
import LlamaCloud from '@llamaindex/llama-cloud';
|
|
5
4
|
import { McpOptions } from "./options.js";
|
|
6
|
-
import { HandlerFunction, McpTool } from "./types.js";
|
|
7
|
-
export
|
|
8
|
-
export { ClientOptions } from '@llamaindex/llama-cloud';
|
|
9
|
-
export declare const newMcpServer: () => Promise<McpServer>;
|
|
5
|
+
import { HandlerFunction, McpRequestContext, ToolCallResult, McpTool } from "./types.js";
|
|
6
|
+
export declare const newMcpServer: (stainlessApiKey: string | undefined) => Promise<McpServer>;
|
|
10
7
|
/**
|
|
11
8
|
* Initializes the provided MCP Server with the given tools and handlers.
|
|
12
9
|
* If not provided, the default client, tools and handlers will be used.
|
|
@@ -15,6 +12,7 @@ export declare function initMcpServer(params: {
|
|
|
15
12
|
server: Server | McpServer;
|
|
16
13
|
clientOptions?: ClientOptions;
|
|
17
14
|
mcpOptions?: McpOptions;
|
|
15
|
+
stainlessApiKey?: string | undefined;
|
|
18
16
|
}): Promise<void>;
|
|
19
17
|
/**
|
|
20
18
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
@@ -23,8 +21,9 @@ export declare function selectTools(options?: McpOptions): McpTool[];
|
|
|
23
21
|
/**
|
|
24
22
|
* Runs the provided handler with the given client and arguments.
|
|
25
23
|
*/
|
|
26
|
-
export declare function executeHandler(handler
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
export declare function executeHandler({ handler, reqContext, args, }: {
|
|
25
|
+
handler: HandlerFunction;
|
|
26
|
+
reqContext: McpRequestContext;
|
|
27
|
+
args: Record<string, unknown> | undefined;
|
|
28
|
+
}): Promise<ToolCallResult>;
|
|
30
29
|
//# sourceMappingURL=server.d.ts.map
|
package/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,yBAAyB;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,yBAAyB;OAKhD,EAAE,UAAU,EAAE;OAEd,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE;AAEtE,eAAO,MAAM,YAAY,GAAU,iBAAiB,MAAM,GAAG,SAAS,uBAUnE,CAAC;AAEJ;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC,iBAiHA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAe3D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GACL,EAAE;IACD,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,cAAc,CAAC,CAE1B"}
|
package/server.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.newMcpServer = void 0;
|
|
8
8
|
exports.initMcpServer = initMcpServer;
|
|
9
9
|
exports.selectTools = selectTools;
|
|
10
10
|
exports.executeHandler = executeHandler;
|
|
@@ -13,38 +13,13 @@ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
|
13
13
|
const llama_cloud_1 = __importDefault(require("@llamaindex/llama-cloud"));
|
|
14
14
|
const code_tool_1 = require("./code-tool.js");
|
|
15
15
|
const docs_search_tool_1 = __importDefault(require("./docs-search-tool.js"));
|
|
16
|
+
const instructions_1 = require("./instructions.js");
|
|
16
17
|
const methods_1 = require("./methods.js");
|
|
17
|
-
async
|
|
18
|
-
// This API key is optional; providing it allows the server to fetch instructions for unreleased versions.
|
|
19
|
-
const stainlessAPIKey = (0, exports.readEnv)('STAINLESS_API_KEY');
|
|
20
|
-
const response = await fetch((0, exports.readEnv)('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/llamacloud-prod', {
|
|
21
|
-
method: 'GET',
|
|
22
|
-
headers: { ...(stainlessAPIKey && { Authorization: stainlessAPIKey }) },
|
|
23
|
-
});
|
|
24
|
-
let instructions;
|
|
25
|
-
if (!response.ok) {
|
|
26
|
-
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
27
|
-
instructions = `
|
|
28
|
-
This is the llamacloud-prod MCP server. You will use Code Mode to help the user perform
|
|
29
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
30
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
31
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
32
|
-
block: it can be as long as you need to get the job done!
|
|
33
|
-
`;
|
|
34
|
-
}
|
|
35
|
-
instructions ??= (await response.json()).instructions;
|
|
36
|
-
instructions = `
|
|
37
|
-
The current time in Unix timestamps is ${Date.now()}.
|
|
38
|
-
|
|
39
|
-
${instructions}
|
|
40
|
-
`;
|
|
41
|
-
return instructions;
|
|
42
|
-
}
|
|
43
|
-
const newMcpServer = async () => new mcp_js_1.McpServer({
|
|
18
|
+
const newMcpServer = async (stainlessApiKey) => new mcp_js_1.McpServer({
|
|
44
19
|
name: 'llamaindex_llama_cloud_api',
|
|
45
|
-
version: '1.
|
|
20
|
+
version: '1.7.0',
|
|
46
21
|
}, {
|
|
47
|
-
instructions: await getInstructions(),
|
|
22
|
+
instructions: await (0, instructions_1.getInstructions)(stainlessApiKey),
|
|
48
23
|
capabilities: { tools: {}, logging: {} },
|
|
49
24
|
});
|
|
50
25
|
exports.newMcpServer = newMcpServer;
|
|
@@ -66,14 +41,33 @@ async function initMcpServer(params) {
|
|
|
66
41
|
warn: logAtLevel('warning'),
|
|
67
42
|
error: logAtLevel('error'),
|
|
68
43
|
};
|
|
69
|
-
let
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
44
|
+
let _client;
|
|
45
|
+
let _clientError;
|
|
46
|
+
let _logLevel;
|
|
47
|
+
const getClient = () => {
|
|
48
|
+
if (_clientError)
|
|
49
|
+
throw _clientError;
|
|
50
|
+
if (!_client) {
|
|
51
|
+
try {
|
|
52
|
+
_client = new llama_cloud_1.default({
|
|
53
|
+
logger,
|
|
54
|
+
...params.clientOptions,
|
|
55
|
+
defaultHeaders: {
|
|
56
|
+
...params.clientOptions?.defaultHeaders,
|
|
57
|
+
'X-Stainless-MCP': 'true',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
if (_logLevel) {
|
|
61
|
+
_client = _client.withOptions({ logLevel: _logLevel });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
_clientError = e instanceof Error ? e : new Error(String(e));
|
|
66
|
+
throw _clientError;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return _client;
|
|
70
|
+
};
|
|
77
71
|
const providedTools = selectTools(params.mcpOptions);
|
|
78
72
|
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
79
73
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
@@ -87,28 +81,55 @@ async function initMcpServer(params) {
|
|
|
87
81
|
if (!mcpTool) {
|
|
88
82
|
throw new Error(`Unknown tool: ${name}`);
|
|
89
83
|
}
|
|
90
|
-
|
|
84
|
+
let client;
|
|
85
|
+
try {
|
|
86
|
+
client = getClient();
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: 'text',
|
|
93
|
+
text: `Failed to initialize client: ${error instanceof Error ? error.message : String(error)}`,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
isError: true,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return executeHandler({
|
|
100
|
+
handler: mcpTool.handler,
|
|
101
|
+
reqContext: {
|
|
102
|
+
client,
|
|
103
|
+
stainlessApiKey: params.stainlessApiKey ?? params.mcpOptions?.stainlessApiKey,
|
|
104
|
+
},
|
|
105
|
+
args,
|
|
106
|
+
});
|
|
91
107
|
});
|
|
92
108
|
server.setRequestHandler(types_js_1.SetLevelRequestSchema, async (request) => {
|
|
93
109
|
const { level } = request.params;
|
|
110
|
+
let logLevel;
|
|
94
111
|
switch (level) {
|
|
95
112
|
case 'debug':
|
|
96
|
-
|
|
113
|
+
logLevel = 'debug';
|
|
97
114
|
break;
|
|
98
115
|
case 'info':
|
|
99
|
-
|
|
116
|
+
logLevel = 'info';
|
|
100
117
|
break;
|
|
101
118
|
case 'notice':
|
|
102
119
|
case 'warning':
|
|
103
|
-
|
|
120
|
+
logLevel = 'warn';
|
|
104
121
|
break;
|
|
105
122
|
case 'error':
|
|
106
|
-
|
|
123
|
+
logLevel = 'error';
|
|
107
124
|
break;
|
|
108
125
|
default:
|
|
109
|
-
|
|
126
|
+
logLevel = 'off';
|
|
110
127
|
break;
|
|
111
128
|
}
|
|
129
|
+
_logLevel = logLevel;
|
|
130
|
+
if (_client) {
|
|
131
|
+
_client = _client.withOptions({ logLevel });
|
|
132
|
+
}
|
|
112
133
|
return {};
|
|
113
134
|
});
|
|
114
135
|
}
|
|
@@ -116,11 +137,13 @@ async function initMcpServer(params) {
|
|
|
116
137
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
117
138
|
*/
|
|
118
139
|
function selectTools(options) {
|
|
119
|
-
const includedTools = [
|
|
120
|
-
|
|
140
|
+
const includedTools = [];
|
|
141
|
+
if (options?.includeCodeTool ?? true) {
|
|
142
|
+
includedTools.push((0, code_tool_1.codeTool)({
|
|
121
143
|
blockedMethods: (0, methods_1.blockedMethodsForCodeTool)(options),
|
|
122
|
-
|
|
123
|
-
|
|
144
|
+
codeExecutionMode: options?.codeExecutionMode ?? 'stainless-sandbox',
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
124
147
|
if (options?.includeDocsTools ?? true) {
|
|
125
148
|
includedTools.push(docs_search_tool_1.default);
|
|
126
149
|
}
|
|
@@ -129,32 +152,7 @@ function selectTools(options) {
|
|
|
129
152
|
/**
|
|
130
153
|
* Runs the provided handler with the given client and arguments.
|
|
131
154
|
*/
|
|
132
|
-
async function executeHandler(handler,
|
|
133
|
-
return await handler(
|
|
155
|
+
async function executeHandler({ handler, reqContext, args, }) {
|
|
156
|
+
return await handler({ reqContext, args: args || {} });
|
|
134
157
|
}
|
|
135
|
-
const readEnv = (env) => {
|
|
136
|
-
if (typeof globalThis.process !== 'undefined') {
|
|
137
|
-
return globalThis.process.env?.[env]?.trim();
|
|
138
|
-
}
|
|
139
|
-
else if (typeof globalThis.Deno !== 'undefined') {
|
|
140
|
-
return globalThis.Deno.env?.get?.(env)?.trim();
|
|
141
|
-
}
|
|
142
|
-
return;
|
|
143
|
-
};
|
|
144
|
-
exports.readEnv = readEnv;
|
|
145
|
-
const readEnvOrError = (env) => {
|
|
146
|
-
let envValue = (0, exports.readEnv)(env);
|
|
147
|
-
if (envValue === undefined) {
|
|
148
|
-
throw new Error(`Environment variable ${env} is not set`);
|
|
149
|
-
}
|
|
150
|
-
return envValue;
|
|
151
|
-
};
|
|
152
|
-
exports.readEnvOrError = readEnvOrError;
|
|
153
|
-
const requireValue = (value, description) => {
|
|
154
|
-
if (value === undefined) {
|
|
155
|
-
throw new Error(`Missing required value: ${description}`);
|
|
156
|
-
}
|
|
157
|
-
return value;
|
|
158
|
-
};
|
|
159
|
-
exports.requireValue = requireValue;
|
|
160
158
|
//# sourceMappingURL=server.js.map
|
package/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAkCtF,sCAsHC;AAKD,kCAeC;AAKD,wCAUC;AAxLD,oEAAoE;AACpE,iEAI4C;AAE5C,0EAAiD;AACjD,8CAAuC;AACvC,6EAAgD;AAChD,oDAAiD;AAEjD,0CAAsD;AAG/C,MAAM,YAAY,GAAG,KAAK,EAAE,eAAmC,EAAE,EAAE,CACxE,IAAI,kBAAS,CACX;IACE,IAAI,EAAE,4BAA4B;IAClC,OAAO,EAAE,OAAO;CACjB,EACD;IACE,YAAY,EAAE,MAAM,IAAA,8BAAe,EAAC,eAAe,CAAC;IACpD,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;CACzC,CACF,CAAC;AAVS,QAAA,YAAY,gBAUrB;AAEJ;;;GAGG;AACI,KAAK,UAAU,aAAa,CAAC,MAKnC;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,YAAY,kBAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC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AAgB,IAAI,IAAI,EAAE,CAAC;QACtC,aAAa,CAAC,IAAI,CAAC,0BAAc,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GAKL;IACC,OAAO,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
package/server.mjs
CHANGED
|
@@ -4,38 +4,13 @@ import { CallToolRequestSchema, ListToolsRequestSchema, SetLevelRequestSchema, }
|
|
|
4
4
|
import LlamaCloud from '@llamaindex/llama-cloud';
|
|
5
5
|
import { codeTool } from "./code-tool.mjs";
|
|
6
6
|
import docsSearchTool from "./docs-search-tool.mjs";
|
|
7
|
+
import { getInstructions } from "./instructions.mjs";
|
|
7
8
|
import { blockedMethodsForCodeTool } from "./methods.mjs";
|
|
8
|
-
async
|
|
9
|
-
// This API key is optional; providing it allows the server to fetch instructions for unreleased versions.
|
|
10
|
-
const stainlessAPIKey = readEnv('STAINLESS_API_KEY');
|
|
11
|
-
const response = await fetch(readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/llamacloud-prod', {
|
|
12
|
-
method: 'GET',
|
|
13
|
-
headers: { ...(stainlessAPIKey && { Authorization: stainlessAPIKey }) },
|
|
14
|
-
});
|
|
15
|
-
let instructions;
|
|
16
|
-
if (!response.ok) {
|
|
17
|
-
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
18
|
-
instructions = `
|
|
19
|
-
This is the llamacloud-prod MCP server. You will use Code Mode to help the user perform
|
|
20
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
21
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
22
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
23
|
-
block: it can be as long as you need to get the job done!
|
|
24
|
-
`;
|
|
25
|
-
}
|
|
26
|
-
instructions ??= (await response.json()).instructions;
|
|
27
|
-
instructions = `
|
|
28
|
-
The current time in Unix timestamps is ${Date.now()}.
|
|
29
|
-
|
|
30
|
-
${instructions}
|
|
31
|
-
`;
|
|
32
|
-
return instructions;
|
|
33
|
-
}
|
|
34
|
-
export const newMcpServer = async () => new McpServer({
|
|
9
|
+
export const newMcpServer = async (stainlessApiKey) => new McpServer({
|
|
35
10
|
name: 'llamaindex_llama_cloud_api',
|
|
36
|
-
version: '1.
|
|
11
|
+
version: '1.7.0',
|
|
37
12
|
}, {
|
|
38
|
-
instructions: await getInstructions(),
|
|
13
|
+
instructions: await getInstructions(stainlessApiKey),
|
|
39
14
|
capabilities: { tools: {}, logging: {} },
|
|
40
15
|
});
|
|
41
16
|
/**
|
|
@@ -56,14 +31,33 @@ export async function initMcpServer(params) {
|
|
|
56
31
|
warn: logAtLevel('warning'),
|
|
57
32
|
error: logAtLevel('error'),
|
|
58
33
|
};
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
34
|
+
let _client;
|
|
35
|
+
let _clientError;
|
|
36
|
+
let _logLevel;
|
|
37
|
+
const getClient = () => {
|
|
38
|
+
if (_clientError)
|
|
39
|
+
throw _clientError;
|
|
40
|
+
if (!_client) {
|
|
41
|
+
try {
|
|
42
|
+
_client = new LlamaCloud({
|
|
43
|
+
logger,
|
|
44
|
+
...params.clientOptions,
|
|
45
|
+
defaultHeaders: {
|
|
46
|
+
...params.clientOptions?.defaultHeaders,
|
|
47
|
+
'X-Stainless-MCP': 'true',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (_logLevel) {
|
|
51
|
+
_client = _client.withOptions({ logLevel: _logLevel });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
_clientError = e instanceof Error ? e : new Error(String(e));
|
|
56
|
+
throw _clientError;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return _client;
|
|
60
|
+
};
|
|
67
61
|
const providedTools = selectTools(params.mcpOptions);
|
|
68
62
|
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
69
63
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
@@ -77,28 +71,55 @@ export async function initMcpServer(params) {
|
|
|
77
71
|
if (!mcpTool) {
|
|
78
72
|
throw new Error(`Unknown tool: ${name}`);
|
|
79
73
|
}
|
|
80
|
-
|
|
74
|
+
let client;
|
|
75
|
+
try {
|
|
76
|
+
client = getClient();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: 'text',
|
|
83
|
+
text: `Failed to initialize client: ${error instanceof Error ? error.message : String(error)}`,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
isError: true,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return executeHandler({
|
|
90
|
+
handler: mcpTool.handler,
|
|
91
|
+
reqContext: {
|
|
92
|
+
client,
|
|
93
|
+
stainlessApiKey: params.stainlessApiKey ?? params.mcpOptions?.stainlessApiKey,
|
|
94
|
+
},
|
|
95
|
+
args,
|
|
96
|
+
});
|
|
81
97
|
});
|
|
82
98
|
server.setRequestHandler(SetLevelRequestSchema, async (request) => {
|
|
83
99
|
const { level } = request.params;
|
|
100
|
+
let logLevel;
|
|
84
101
|
switch (level) {
|
|
85
102
|
case 'debug':
|
|
86
|
-
|
|
103
|
+
logLevel = 'debug';
|
|
87
104
|
break;
|
|
88
105
|
case 'info':
|
|
89
|
-
|
|
106
|
+
logLevel = 'info';
|
|
90
107
|
break;
|
|
91
108
|
case 'notice':
|
|
92
109
|
case 'warning':
|
|
93
|
-
|
|
110
|
+
logLevel = 'warn';
|
|
94
111
|
break;
|
|
95
112
|
case 'error':
|
|
96
|
-
|
|
113
|
+
logLevel = 'error';
|
|
97
114
|
break;
|
|
98
115
|
default:
|
|
99
|
-
|
|
116
|
+
logLevel = 'off';
|
|
100
117
|
break;
|
|
101
118
|
}
|
|
119
|
+
_logLevel = logLevel;
|
|
120
|
+
if (_client) {
|
|
121
|
+
_client = _client.withOptions({ logLevel });
|
|
122
|
+
}
|
|
102
123
|
return {};
|
|
103
124
|
});
|
|
104
125
|
}
|
|
@@ -106,11 +127,13 @@ export async function initMcpServer(params) {
|
|
|
106
127
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
107
128
|
*/
|
|
108
129
|
export function selectTools(options) {
|
|
109
|
-
const includedTools = [
|
|
110
|
-
|
|
130
|
+
const includedTools = [];
|
|
131
|
+
if (options?.includeCodeTool ?? true) {
|
|
132
|
+
includedTools.push(codeTool({
|
|
111
133
|
blockedMethods: blockedMethodsForCodeTool(options),
|
|
112
|
-
|
|
113
|
-
|
|
134
|
+
codeExecutionMode: options?.codeExecutionMode ?? 'stainless-sandbox',
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
114
137
|
if (options?.includeDocsTools ?? true) {
|
|
115
138
|
includedTools.push(docsSearchTool);
|
|
116
139
|
}
|
|
@@ -119,29 +142,7 @@ export function selectTools(options) {
|
|
|
119
142
|
/**
|
|
120
143
|
* Runs the provided handler with the given client and arguments.
|
|
121
144
|
*/
|
|
122
|
-
export async function executeHandler(handler,
|
|
123
|
-
return await handler(
|
|
145
|
+
export async function executeHandler({ handler, reqContext, args, }) {
|
|
146
|
+
return await handler({ reqContext, args: args || {} });
|
|
124
147
|
}
|
|
125
|
-
export const readEnv = (env) => {
|
|
126
|
-
if (typeof globalThis.process !== 'undefined') {
|
|
127
|
-
return globalThis.process.env?.[env]?.trim();
|
|
128
|
-
}
|
|
129
|
-
else if (typeof globalThis.Deno !== 'undefined') {
|
|
130
|
-
return globalThis.Deno.env?.get?.(env)?.trim();
|
|
131
|
-
}
|
|
132
|
-
return;
|
|
133
|
-
};
|
|
134
|
-
export const readEnvOrError = (env) => {
|
|
135
|
-
let envValue = readEnv(env);
|
|
136
|
-
if (envValue === undefined) {
|
|
137
|
-
throw new Error(`Environment variable ${env} is not set`);
|
|
138
|
-
}
|
|
139
|
-
return envValue;
|
|
140
|
-
};
|
|
141
|
-
export const requireValue = (value, description) => {
|
|
142
|
-
if (value === undefined) {
|
|
143
|
-
throw new Error(`Missing required value: ${description}`);
|
|
144
|
-
}
|
|
145
|
-
return value;
|
|
146
|
-
};
|
|
147
148
|
//# sourceMappingURL=server.mjs.map
|