@llamaindex/llama-cloud-mcp 0.14.1

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 (94) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +101 -0
  3. package/code-tool-types.d.mts +13 -0
  4. package/code-tool-types.d.mts.map +1 -0
  5. package/code-tool-types.d.ts +13 -0
  6. package/code-tool-types.d.ts.map +1 -0
  7. package/code-tool-types.js +4 -0
  8. package/code-tool-types.js.map +1 -0
  9. package/code-tool-types.mjs +3 -0
  10. package/code-tool-types.mjs.map +1 -0
  11. package/code-tool.d.mts +12 -0
  12. package/code-tool.d.mts.map +1 -0
  13. package/code-tool.d.ts +12 -0
  14. package/code-tool.d.ts.map +1 -0
  15. package/code-tool.js +85 -0
  16. package/code-tool.js.map +1 -0
  17. package/code-tool.mjs +82 -0
  18. package/code-tool.mjs.map +1 -0
  19. package/docs-search-tool.d.mts +50 -0
  20. package/docs-search-tool.d.mts.map +1 -0
  21. package/docs-search-tool.d.ts +50 -0
  22. package/docs-search-tool.d.ts.map +1 -0
  23. package/docs-search-tool.js +51 -0
  24. package/docs-search-tool.js.map +1 -0
  25. package/docs-search-tool.mjs +47 -0
  26. package/docs-search-tool.mjs.map +1 -0
  27. package/headers.d.mts +4 -0
  28. package/headers.d.mts.map +1 -0
  29. package/headers.d.ts +4 -0
  30. package/headers.d.ts.map +1 -0
  31. package/headers.js +22 -0
  32. package/headers.js.map +1 -0
  33. package/headers.mjs +18 -0
  34. package/headers.mjs.map +1 -0
  35. package/http.d.mts +9 -0
  36. package/http.d.mts.map +1 -0
  37. package/http.d.ts +9 -0
  38. package/http.d.ts.map +1 -0
  39. package/http.js +91 -0
  40. package/http.js.map +1 -0
  41. package/http.mjs +83 -0
  42. package/http.mjs.map +1 -0
  43. package/index.d.mts +3 -0
  44. package/index.d.mts.map +1 -0
  45. package/index.d.ts +3 -0
  46. package/index.d.ts.map +1 -0
  47. package/index.js +55 -0
  48. package/index.js.map +1 -0
  49. package/index.mjs +53 -0
  50. package/index.mjs.map +1 -0
  51. package/options.d.mts +11 -0
  52. package/options.d.mts.map +1 -0
  53. package/options.d.ts +11 -0
  54. package/options.d.ts.map +1 -0
  55. package/options.js +72 -0
  56. package/options.js.map +1 -0
  57. package/options.mjs +65 -0
  58. package/options.mjs.map +1 -0
  59. package/package.json +162 -0
  60. package/server.d.mts +30 -0
  61. package/server.d.mts.map +1 -0
  62. package/server.d.ts +30 -0
  63. package/server.d.ts.map +1 -0
  64. package/server.js +121 -0
  65. package/server.js.map +1 -0
  66. package/server.mjs +109 -0
  67. package/server.mjs.map +1 -0
  68. package/src/code-tool-types.ts +15 -0
  69. package/src/code-tool.ts +96 -0
  70. package/src/docs-search-tool.ts +59 -0
  71. package/src/headers.ts +25 -0
  72. package/src/http.ts +109 -0
  73. package/src/index.ts +61 -0
  74. package/src/options.ts +92 -0
  75. package/src/server.ts +147 -0
  76. package/src/stdio.ts +12 -0
  77. package/src/tsconfig.json +11 -0
  78. package/src/types.ts +115 -0
  79. package/stdio.d.mts +2 -0
  80. package/stdio.d.mts.map +1 -0
  81. package/stdio.d.ts +2 -0
  82. package/stdio.d.ts.map +1 -0
  83. package/stdio.js +14 -0
  84. package/stdio.js.map +1 -0
  85. package/stdio.mjs +10 -0
  86. package/stdio.mjs.map +1 -0
  87. package/types.d.mts +52 -0
  88. package/types.d.mts.map +1 -0
  89. package/types.d.ts +52 -0
  90. package/types.d.ts.map +1 -0
  91. package/types.js +58 -0
  92. package/types.js.map +1 -0
  93. package/types.mjs +53 -0
  94. package/types.mjs.map +1 -0
package/package.json ADDED
@@ -0,0 +1,162 @@
1
+ {
2
+ "name": "@llamaindex/llama-cloud-mcp",
3
+ "version": "0.14.1",
4
+ "description": "The official MCP Server for the Llama Cloud API",
5
+ "author": "Llama Cloud <>",
6
+ "types": "./index.d.ts",
7
+ "main": "./index.js",
8
+ "type": "commonjs",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/run-llama/llama-cloud-ts.git",
12
+ "directory": "packages/mcp-server"
13
+ },
14
+ "homepage": "https://github.com/run-llama/llama-cloud-ts/tree/main/packages/mcp-server#readme",
15
+ "license": "MIT",
16
+ "packageManager": "yarn@1.22.22",
17
+ "private": false,
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "scripts": {
22
+ "test": "jest",
23
+ "build": "bash ./build",
24
+ "format": "prettier --write --cache --cache-strategy metadata . !dist",
25
+ "tsn": "ts-node -r tsconfig-paths/register",
26
+ "lint": "eslint --ext ts,js .",
27
+ "fix": "eslint --fix --ext ts,js ."
28
+ },
29
+ "dependencies": {
30
+ "@llamaindex/llama-cloud": "^0.14.1",
31
+ "@cloudflare/cabidela": "^0.2.4",
32
+ "@modelcontextprotocol/sdk": "^1.24.0",
33
+ "@valtown/deno-http-worker": "^0.0.21",
34
+ "cors": "^2.8.5",
35
+ "express": "^5.1.0",
36
+ "fuse.js": "^7.1.0",
37
+ "jq-web": "https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz",
38
+ "qs": "^6.14.0",
39
+ "typescript": "5.8.3",
40
+ "yargs": "^17.7.2",
41
+ "zod": "^3.25.20",
42
+ "zod-to-json-schema": "^3.24.5",
43
+ "zod-validation-error": "^4.0.1"
44
+ },
45
+ "bin": {
46
+ "mcp-server": "./index.js"
47
+ },
48
+ "imports": {
49
+ "@llamaindex/llama-cloud-mcp": ".",
50
+ "@llamaindex/llama-cloud-mcp/*": "./src/*"
51
+ },
52
+ "exports": {
53
+ ".": {
54
+ "require": {
55
+ "types": "./index.d.ts",
56
+ "default": "./index.js"
57
+ },
58
+ "types": "./index.d.mts",
59
+ "default": "./index.mjs"
60
+ },
61
+ "./code-tool-types": {
62
+ "import": "./code-tool-types.mjs",
63
+ "require": "./code-tool-types.js"
64
+ },
65
+ "./code-tool-types.js": {
66
+ "default": "./code-tool-types.js"
67
+ },
68
+ "./code-tool-types.mjs": {
69
+ "default": "./code-tool-types.mjs"
70
+ },
71
+ "./code-tool": {
72
+ "import": "./code-tool.mjs",
73
+ "require": "./code-tool.js"
74
+ },
75
+ "./code-tool.js": {
76
+ "default": "./code-tool.js"
77
+ },
78
+ "./code-tool.mjs": {
79
+ "default": "./code-tool.mjs"
80
+ },
81
+ "./docs-search-tool": {
82
+ "import": "./docs-search-tool.mjs",
83
+ "require": "./docs-search-tool.js"
84
+ },
85
+ "./docs-search-tool.js": {
86
+ "default": "./docs-search-tool.js"
87
+ },
88
+ "./docs-search-tool.mjs": {
89
+ "default": "./docs-search-tool.mjs"
90
+ },
91
+ "./headers": {
92
+ "import": "./headers.mjs",
93
+ "require": "./headers.js"
94
+ },
95
+ "./headers.js": {
96
+ "default": "./headers.js"
97
+ },
98
+ "./headers.mjs": {
99
+ "default": "./headers.mjs"
100
+ },
101
+ "./http": {
102
+ "import": "./http.mjs",
103
+ "require": "./http.js"
104
+ },
105
+ "./http.js": {
106
+ "default": "./http.js"
107
+ },
108
+ "./http.mjs": {
109
+ "default": "./http.mjs"
110
+ },
111
+ "./index": {
112
+ "import": "./index.mjs",
113
+ "require": "./index.js"
114
+ },
115
+ "./index.js": {
116
+ "default": "./index.js"
117
+ },
118
+ "./index.mjs": {
119
+ "default": "./index.mjs"
120
+ },
121
+ "./options": {
122
+ "import": "./options.mjs",
123
+ "require": "./options.js"
124
+ },
125
+ "./options.js": {
126
+ "default": "./options.js"
127
+ },
128
+ "./options.mjs": {
129
+ "default": "./options.mjs"
130
+ },
131
+ "./server": {
132
+ "import": "./server.mjs",
133
+ "require": "./server.js"
134
+ },
135
+ "./server.js": {
136
+ "default": "./server.js"
137
+ },
138
+ "./server.mjs": {
139
+ "default": "./server.mjs"
140
+ },
141
+ "./stdio": {
142
+ "import": "./stdio.mjs",
143
+ "require": "./stdio.js"
144
+ },
145
+ "./stdio.js": {
146
+ "default": "./stdio.js"
147
+ },
148
+ "./stdio.mjs": {
149
+ "default": "./stdio.mjs"
150
+ },
151
+ "./types": {
152
+ "import": "./types.mjs",
153
+ "require": "./types.js"
154
+ },
155
+ "./types.js": {
156
+ "default": "./types.js"
157
+ },
158
+ "./types.mjs": {
159
+ "default": "./types.mjs"
160
+ }
161
+ }
162
+ }
package/server.d.mts ADDED
@@ -0,0 +1,30 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { ClientOptions } from '@llamaindex/llama-cloud';
4
+ import LlamaCloud from '@llamaindex/llama-cloud';
5
+ import { McpOptions } from "./options.mjs";
6
+ import { HandlerFunction, McpTool } from "./types.mjs";
7
+ export { McpOptions } from "./options.mjs";
8
+ export { ClientOptions } from '@llamaindex/llama-cloud';
9
+ export declare const newMcpServer: () => McpServer;
10
+ export declare const server: McpServer;
11
+ /**
12
+ * Initializes the provided MCP Server with the given tools and handlers.
13
+ * If not provided, the default client, tools and handlers will be used.
14
+ */
15
+ export declare function initMcpServer(params: {
16
+ server: Server | McpServer;
17
+ clientOptions?: ClientOptions;
18
+ mcpOptions?: McpOptions;
19
+ }): void;
20
+ /**
21
+ * Selects the tools to include in the MCP Server based on the provided options.
22
+ */
23
+ export declare function selectTools(options?: McpOptions): McpTool[];
24
+ /**
25
+ * Runs the provided handler with the given client and arguments.
26
+ */
27
+ export declare function executeHandler(handler: HandlerFunction, client: LlamaCloud, args: Record<string, unknown> | undefined): Promise<import("./types").ToolCallResult>;
28
+ export declare const readEnv: (env: string) => string | undefined;
29
+ export declare const readEnvOrError: (env: string) => string;
30
+ //# sourceMappingURL=server.d.mts.map
@@ -0,0 +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;OAChD,UAAU,MAAM,yBAAyB;OAGzC,EAAE,UAAU,EAAE;OACd,EAAE,eAAe,EAAE,OAAO,EAAE;OAE5B,EAAE,UAAU,EAAE;OACd,EAAE,aAAa,EAAE,MAAM,yBAAyB;AAEvD,eAAO,MAAM,YAAY,iBAOtB,CAAC;AAGJ,eAAO,MAAM,MAAM,WAAiB,CAAC;AAErC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,QAoEA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAM3D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,6CAG1C;AAED,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAO9C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,MAM5C,CAAC"}
package/server.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { ClientOptions } from '@llamaindex/llama-cloud';
4
+ import LlamaCloud from '@llamaindex/llama-cloud';
5
+ import { McpOptions } from "./options.js";
6
+ import { HandlerFunction, McpTool } from "./types.js";
7
+ export { McpOptions } from "./options.js";
8
+ export { ClientOptions } from '@llamaindex/llama-cloud';
9
+ export declare const newMcpServer: () => McpServer;
10
+ export declare const server: McpServer;
11
+ /**
12
+ * Initializes the provided MCP Server with the given tools and handlers.
13
+ * If not provided, the default client, tools and handlers will be used.
14
+ */
15
+ export declare function initMcpServer(params: {
16
+ server: Server | McpServer;
17
+ clientOptions?: ClientOptions;
18
+ mcpOptions?: McpOptions;
19
+ }): void;
20
+ /**
21
+ * Selects the tools to include in the MCP Server based on the provided options.
22
+ */
23
+ export declare function selectTools(options?: McpOptions): McpTool[];
24
+ /**
25
+ * Runs the provided handler with the given client and arguments.
26
+ */
27
+ export declare function executeHandler(handler: HandlerFunction, client: LlamaCloud, args: Record<string, unknown> | undefined): Promise<import("./types").ToolCallResult>;
28
+ export declare const readEnv: (env: string) => string | undefined;
29
+ export declare const readEnvOrError: (env: string) => string;
30
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +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;OAChD,UAAU,MAAM,yBAAyB;OAGzC,EAAE,UAAU,EAAE;OACd,EAAE,eAAe,EAAE,OAAO,EAAE;OAE5B,EAAE,UAAU,EAAE;OACd,EAAE,aAAa,EAAE,MAAM,yBAAyB;AAEvD,eAAO,MAAM,YAAY,iBAOtB,CAAC;AAGJ,eAAO,MAAM,MAAM,WAAiB,CAAC;AAErC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,QAoEA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAM3D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,6CAG1C;AAED,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAO9C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,MAM5C,CAAC"}
package/server.js ADDED
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.readEnvOrError = exports.readEnv = exports.server = exports.newMcpServer = void 0;
8
+ exports.initMcpServer = initMcpServer;
9
+ exports.selectTools = selectTools;
10
+ exports.executeHandler = executeHandler;
11
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
12
+ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
13
+ const llama_cloud_1 = __importDefault(require("@llamaindex/llama-cloud"));
14
+ const code_tool_1 = require("./code-tool.js");
15
+ const docs_search_tool_1 = __importDefault(require("./docs-search-tool.js"));
16
+ const newMcpServer = () => new mcp_js_1.McpServer({
17
+ name: 'llamaindex_llama_cloud_api',
18
+ version: '0.14.1',
19
+ }, { capabilities: { tools: {}, logging: {} } });
20
+ exports.newMcpServer = newMcpServer;
21
+ // Create server instance
22
+ exports.server = (0, exports.newMcpServer)();
23
+ /**
24
+ * Initializes the provided MCP Server with the given tools and handlers.
25
+ * If not provided, the default client, tools and handlers will be used.
26
+ */
27
+ function initMcpServer(params) {
28
+ const server = params.server instanceof mcp_js_1.McpServer ? params.server.server : params.server;
29
+ const logAtLevel = (level) => (message, ...rest) => {
30
+ void server.sendLoggingMessage({
31
+ level,
32
+ data: { message, rest },
33
+ });
34
+ };
35
+ const logger = {
36
+ debug: logAtLevel('debug'),
37
+ info: logAtLevel('info'),
38
+ warn: logAtLevel('warning'),
39
+ error: logAtLevel('error'),
40
+ };
41
+ let client = new llama_cloud_1.default({
42
+ logger,
43
+ ...params.clientOptions,
44
+ defaultHeaders: {
45
+ ...params.clientOptions?.defaultHeaders,
46
+ 'X-Stainless-MCP': 'true',
47
+ },
48
+ });
49
+ const providedTools = selectTools(params.mcpOptions);
50
+ const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
51
+ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
52
+ return {
53
+ tools: providedTools.map((mcpTool) => mcpTool.tool),
54
+ };
55
+ });
56
+ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
57
+ const { name, arguments: args } = request.params;
58
+ const mcpTool = toolMap[name];
59
+ if (!mcpTool) {
60
+ throw new Error(`Unknown tool: ${name}`);
61
+ }
62
+ return executeHandler(mcpTool.handler, client, args);
63
+ });
64
+ server.setRequestHandler(types_js_1.SetLevelRequestSchema, async (request) => {
65
+ const { level } = request.params;
66
+ switch (level) {
67
+ case 'debug':
68
+ client = client.withOptions({ logLevel: 'debug' });
69
+ break;
70
+ case 'info':
71
+ client = client.withOptions({ logLevel: 'info' });
72
+ break;
73
+ case 'notice':
74
+ case 'warning':
75
+ client = client.withOptions({ logLevel: 'warn' });
76
+ break;
77
+ case 'error':
78
+ client = client.withOptions({ logLevel: 'error' });
79
+ break;
80
+ default:
81
+ client = client.withOptions({ logLevel: 'off' });
82
+ break;
83
+ }
84
+ return {};
85
+ });
86
+ }
87
+ /**
88
+ * Selects the tools to include in the MCP Server based on the provided options.
89
+ */
90
+ function selectTools(options) {
91
+ const includedTools = [(0, code_tool_1.codeTool)()];
92
+ if (options?.includeDocsTools ?? true) {
93
+ includedTools.push(docs_search_tool_1.default);
94
+ }
95
+ return includedTools;
96
+ }
97
+ /**
98
+ * Runs the provided handler with the given client and arguments.
99
+ */
100
+ async function executeHandler(handler, client, args) {
101
+ return await handler(client, args || {});
102
+ }
103
+ const readEnv = (env) => {
104
+ if (typeof globalThis.process !== 'undefined') {
105
+ return globalThis.process.env?.[env]?.trim();
106
+ }
107
+ else if (typeof globalThis.Deno !== 'undefined') {
108
+ return globalThis.Deno.env?.get?.(env)?.trim();
109
+ }
110
+ return;
111
+ };
112
+ exports.readEnv = readEnv;
113
+ const readEnvOrError = (env) => {
114
+ let envValue = (0, exports.readEnv)(env);
115
+ if (envValue === undefined) {
116
+ throw new Error(`Environment variable ${env} is not set`);
117
+ }
118
+ return envValue;
119
+ };
120
+ exports.readEnvOrError = readEnvOrError;
121
+ //# sourceMappingURL=server.js.map
package/server.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAmCtF,sCAwEC;AAKD,kCAMC;AAKD,wCAMC;AA9HD,oEAAoE;AACpE,iEAI4C;AAE5C,0EAAiD;AACjD,8CAAuC;AACvC,6EAAgD;AAOzC,MAAM,YAAY,GAAG,GAAG,EAAE,CAC/B,IAAI,kBAAS,CACX;IACE,IAAI,EAAE,4BAA4B;IAClC,OAAO,EAAE,QAAQ;CAClB,EACD,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAC7C,CAAC;AAPS,QAAA,YAAY,gBAOrB;AAEJ,yBAAyB;AACZ,QAAA,MAAM,GAAG,IAAA,oBAAY,GAAE,CAAC;AAErC;;;GAGG;AACH,SAAgB,aAAa,CAAC,MAI7B;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,YAAY,kBAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IAEzF,MAAM,UAAU,GACd,CAAC,KAA6C,EAAE,EAAE,CAClD,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QACtC,KAAK,MAAM,CAAC,kBAAkB,CAAC;YAC7B,KAAK;YACL,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;SACxB,CAAC,CAAC;IACL,CAAC,CAAC;IACJ,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,U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AAC,CAAC;AAC3C,CAAC;AAEM,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QACvD,OAAQ,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IACxD,CAAC;SAAM,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC3D,OAAQ,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO;AACT,CAAC,CAAC;AAPW,QAAA,OAAO,WAOlB;AAEK,MAAM,cAAc,GAAG,CAAC,GAAW,EAAU,EAAE;IACpD,IAAI,QAAQ,GAAG,IAAA,eAAO,EAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,aAAa,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB"}
package/server.mjs ADDED
@@ -0,0 +1,109 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { CallToolRequestSchema, ListToolsRequestSchema, SetLevelRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
4
+ import LlamaCloud from '@llamaindex/llama-cloud';
5
+ import { codeTool } from "./code-tool.mjs";
6
+ import docsSearchTool from "./docs-search-tool.mjs";
7
+ export const newMcpServer = () => new McpServer({
8
+ name: 'llamaindex_llama_cloud_api',
9
+ version: '0.14.1',
10
+ }, { capabilities: { tools: {}, logging: {} } });
11
+ // Create server instance
12
+ export const server = newMcpServer();
13
+ /**
14
+ * Initializes the provided MCP Server with the given tools and handlers.
15
+ * If not provided, the default client, tools and handlers will be used.
16
+ */
17
+ export function initMcpServer(params) {
18
+ const server = params.server instanceof McpServer ? params.server.server : params.server;
19
+ const logAtLevel = (level) => (message, ...rest) => {
20
+ void server.sendLoggingMessage({
21
+ level,
22
+ data: { message, rest },
23
+ });
24
+ };
25
+ const logger = {
26
+ debug: logAtLevel('debug'),
27
+ info: logAtLevel('info'),
28
+ warn: logAtLevel('warning'),
29
+ error: logAtLevel('error'),
30
+ };
31
+ let client = new LlamaCloud({
32
+ logger,
33
+ ...params.clientOptions,
34
+ defaultHeaders: {
35
+ ...params.clientOptions?.defaultHeaders,
36
+ 'X-Stainless-MCP': 'true',
37
+ },
38
+ });
39
+ const providedTools = selectTools(params.mcpOptions);
40
+ const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
41
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
42
+ return {
43
+ tools: providedTools.map((mcpTool) => mcpTool.tool),
44
+ };
45
+ });
46
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
47
+ const { name, arguments: args } = request.params;
48
+ const mcpTool = toolMap[name];
49
+ if (!mcpTool) {
50
+ throw new Error(`Unknown tool: ${name}`);
51
+ }
52
+ return executeHandler(mcpTool.handler, client, args);
53
+ });
54
+ server.setRequestHandler(SetLevelRequestSchema, async (request) => {
55
+ const { level } = request.params;
56
+ switch (level) {
57
+ case 'debug':
58
+ client = client.withOptions({ logLevel: 'debug' });
59
+ break;
60
+ case 'info':
61
+ client = client.withOptions({ logLevel: 'info' });
62
+ break;
63
+ case 'notice':
64
+ case 'warning':
65
+ client = client.withOptions({ logLevel: 'warn' });
66
+ break;
67
+ case 'error':
68
+ client = client.withOptions({ logLevel: 'error' });
69
+ break;
70
+ default:
71
+ client = client.withOptions({ logLevel: 'off' });
72
+ break;
73
+ }
74
+ return {};
75
+ });
76
+ }
77
+ /**
78
+ * Selects the tools to include in the MCP Server based on the provided options.
79
+ */
80
+ export function selectTools(options) {
81
+ const includedTools = [codeTool()];
82
+ if (options?.includeDocsTools ?? true) {
83
+ includedTools.push(docsSearchTool);
84
+ }
85
+ return includedTools;
86
+ }
87
+ /**
88
+ * Runs the provided handler with the given client and arguments.
89
+ */
90
+ export async function executeHandler(handler, client, args) {
91
+ return await handler(client, args || {});
92
+ }
93
+ export const readEnv = (env) => {
94
+ if (typeof globalThis.process !== 'undefined') {
95
+ return globalThis.process.env?.[env]?.trim();
96
+ }
97
+ else if (typeof globalThis.Deno !== 'undefined') {
98
+ return globalThis.Deno.env?.get?.(env)?.trim();
99
+ }
100
+ return;
101
+ };
102
+ export const readEnvOrError = (env) => {
103
+ let envValue = readEnv(env);
104
+ if (envValue === undefined) {
105
+ throw new Error(`Environment variable ${env} is not set`);
106
+ }
107
+ return envValue;
108
+ };
109
+ //# sourceMappingURL=server.mjs.map
package/server.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAC5D,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC;OAEpC,UAAU,MAAM,yBAAyB;OACzC,EAAE,QAAQ,EAAE;OACZ,cAAc;AAOrB,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAC/B,IAAI,SAAS,CACX;IACE,IAAI,EAAE,4BAA4B;IAClC,OAAO,EAAE,QAAQ;CAClB,EACD,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAC7C,CAAC;AAEJ,yBAAyB;AACzB,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAI7B;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,YAAY,SAA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 export type WorkerInput = {
6
+ project_name: string;
7
+ code: string;
8
+ client_opts: ClientOptions;
9
+ };
10
+ export type WorkerOutput = {
11
+ is_error: boolean;
12
+ result: unknown | null;
13
+ log_lines: string[];
14
+ err_lines: string[];
15
+ };
@@ -0,0 +1,96 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { McpTool, Metadata, ToolCallResult, asErrorResult, asTextContentResult } from './types';
4
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
5
+ import { readEnv, readEnvOrError } from './server';
6
+ import { WorkerInput, WorkerOutput } from './code-tool-types';
7
+
8
+ const prompt = `Runs JavaScript code to interact with the Llama Cloud API.
9
+
10
+ You are a skilled programmer writing code to interface with the service.
11
+ Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
12
+ For example:
13
+
14
+ \`\`\`
15
+ async function run(client) {
16
+ const parsing = await client.parsing.create({
17
+ tier: 'agentic',
18
+ version: 'latest',
19
+ file_id: 'abc1234',
20
+ });
21
+
22
+ console.log(parsing.id);
23
+ }
24
+ \`\`\`
25
+
26
+ You will be returned anything that your function returns, plus the results of any console.log statements.
27
+ Do not add try-catch blocks for single API calls. The tool will handle errors for you.
28
+ Do not add comments unless necessary for generating better code.
29
+ Code will run in a container, and cannot interact with the network outside of the given SDK client.
30
+ Variables will not persist between calls, so make sure to return or log any data you might need later.`;
31
+
32
+ /**
33
+ * A tool that runs code against a copy of the SDK.
34
+ *
35
+ * Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
36
+ * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
37
+ * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
38
+ *
39
+ * @param endpoints - The endpoints to include in the list.
40
+ */
41
+ export function codeTool(): McpTool {
42
+ const metadata: Metadata = { resource: 'all', operation: 'write', tags: [] };
43
+ const tool: Tool = {
44
+ name: 'execute',
45
+ description: prompt,
46
+ inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
47
+ };
48
+ const handler = async (_: unknown, args: any): Promise<ToolCallResult> => {
49
+ const code = args.code as string;
50
+
51
+ // this is not required, but passing a Stainless API key for the matching project_name
52
+ // will allow you to run code-mode queries against non-published versions of your SDK.
53
+ const stainlessAPIKey = readEnv('STAINLESS_API_KEY');
54
+ const codeModeEndpoint =
55
+ readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
56
+
57
+ const res = await fetch(codeModeEndpoint, {
58
+ method: 'POST',
59
+ headers: {
60
+ ...(stainlessAPIKey && { Authorization: stainlessAPIKey }),
61
+ 'Content-Type': 'application/json',
62
+ client_envs: JSON.stringify({
63
+ LLAMA_CLOUD_API_KEY: readEnvOrError('LLAMA_CLOUD_API_KEY'),
64
+ LLAMA_CLOUD_BASE_URL: readEnv('LLAMA_CLOUD_BASE_URL'),
65
+ }),
66
+ },
67
+ body: JSON.stringify({
68
+ project_name: 'llamacloud-prod',
69
+ code,
70
+ client_opts: {},
71
+ } satisfies WorkerInput),
72
+ });
73
+
74
+ if (!res.ok) {
75
+ throw new Error(
76
+ `${res.status}: ${
77
+ res.statusText
78
+ } error when trying to contact Code Tool server. Details: ${await res.text()}`,
79
+ );
80
+ }
81
+
82
+ const { is_error, result, log_lines, err_lines } = (await res.json()) as WorkerOutput;
83
+ const hasLogs = log_lines.length > 0 || err_lines.length > 0;
84
+ const output = {
85
+ result,
86
+ ...(log_lines.length > 0 && { log_lines }),
87
+ ...(err_lines.length > 0 && { err_lines }),
88
+ };
89
+ if (is_error) {
90
+ return asErrorResult(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
91
+ }
92
+ return asTextContentResult(output);
93
+ };
94
+
95
+ return { metadata, tool, handler };
96
+ }
@@ -0,0 +1,59 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { Metadata, asTextContentResult } from './types';
4
+
5
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
6
+
7
+ export const metadata: Metadata = {
8
+ resource: 'all',
9
+ operation: 'read',
10
+ tags: [],
11
+ httpMethod: 'get',
12
+ };
13
+
14
+ export const tool: Tool = {
15
+ name: 'search_docs',
16
+ description: 'Search for documentation for how to use the client to interact with the API.',
17
+ inputSchema: {
18
+ type: 'object',
19
+ properties: {
20
+ query: {
21
+ type: 'string',
22
+ description: 'The query to search for.',
23
+ },
24
+ language: {
25
+ type: 'string',
26
+ description: 'The language for the SDK to search for.',
27
+ enum: ['http', 'python', 'go', 'typescript', 'javascript', 'terraform', 'ruby', 'java', 'kotlin'],
28
+ },
29
+ detail: {
30
+ type: 'string',
31
+ description: 'The amount of detail to return.',
32
+ enum: ['default', 'verbose'],
33
+ },
34
+ },
35
+ required: ['query', 'language'],
36
+ },
37
+ annotations: {
38
+ readOnlyHint: true,
39
+ },
40
+ };
41
+
42
+ const docsSearchURL =
43
+ process.env['DOCS_SEARCH_URL'] || 'https://api.stainless.com/api/projects/llamacloud-prod/docs/search';
44
+
45
+ export const handler = async (_: unknown, args: Record<string, unknown> | undefined) => {
46
+ const body = args as any;
47
+ const query = new URLSearchParams(body).toString();
48
+ const result = await fetch(`${docsSearchURL}?${query}`);
49
+
50
+ if (!result.ok) {
51
+ throw new Error(
52
+ `${result.status}: ${result.statusText} when using doc search tool. Details: ${await result.text()}`,
53
+ );
54
+ }
55
+
56
+ return asTextContentResult(await result.json());
57
+ };
58
+
59
+ export default { metadata, tool, handler };