@llamaindex/llama-cloud-mcp 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/auth.d.mts +6 -0
  2. package/auth.d.mts.map +1 -0
  3. package/auth.d.ts +6 -0
  4. package/auth.d.ts.map +1 -0
  5. package/{headers.mjs → auth.js} +18 -2
  6. package/auth.js.map +1 -0
  7. package/{headers.js → auth.mjs} +13 -6
  8. package/auth.mjs.map +1 -0
  9. package/code-tool.d.mts +4 -1
  10. package/code-tool.d.mts.map +1 -1
  11. package/code-tool.d.ts +4 -1
  12. package/code-tool.d.ts.map +1 -1
  13. package/code-tool.js +22 -10
  14. package/code-tool.js.map +1 -1
  15. package/code-tool.mjs +20 -8
  16. package/code-tool.mjs.map +1 -1
  17. package/docs-search-tool.d.mts +9 -3
  18. package/docs-search-tool.d.mts.map +1 -1
  19. package/docs-search-tool.d.ts +9 -3
  20. package/docs-search-tool.d.ts.map +1 -1
  21. package/docs-search-tool.js +6 -2
  22. package/docs-search-tool.js.map +1 -1
  23. package/docs-search-tool.mjs +6 -2
  24. package/docs-search-tool.mjs.map +1 -1
  25. package/http.d.mts +2 -2
  26. package/http.d.mts.map +1 -1
  27. package/http.d.ts +2 -2
  28. package/http.d.ts.map +1 -1
  29. package/http.js +14 -8
  30. package/http.js.map +1 -1
  31. package/http.mjs +14 -8
  32. package/http.mjs.map +1 -1
  33. package/index.js +1 -1
  34. package/index.js.map +1 -1
  35. package/index.mjs +1 -1
  36. package/index.mjs.map +1 -1
  37. package/methods.d.mts +10 -0
  38. package/methods.d.mts.map +1 -0
  39. package/methods.d.ts +10 -0
  40. package/methods.d.ts.map +1 -0
  41. package/methods.js +791 -0
  42. package/methods.js.map +1 -0
  43. package/methods.mjs +787 -0
  44. package/methods.mjs.map +1 -0
  45. package/options.d.mts +4 -0
  46. package/options.d.mts.map +1 -1
  47. package/options.d.ts +4 -0
  48. package/options.d.ts.map +1 -1
  49. package/options.js +25 -0
  50. package/options.js.map +1 -1
  51. package/options.mjs +25 -0
  52. package/options.mjs.map +1 -1
  53. package/package.json +32 -12
  54. package/server.d.mts +8 -9
  55. package/server.d.mts.map +1 -1
  56. package/server.d.ts +8 -9
  57. package/server.d.ts.map +1 -1
  58. package/server.js +30 -42
  59. package/server.js.map +1 -1
  60. package/server.mjs +28 -37
  61. package/server.mjs.map +1 -1
  62. package/src/{headers.ts → auth.ts} +16 -1
  63. package/src/code-tool.ts +37 -9
  64. package/src/docs-search-tool.ts +13 -4
  65. package/src/http.ts +22 -8
  66. package/src/index.ts +1 -1
  67. package/src/methods.ts +812 -0
  68. package/src/options.ts +34 -0
  69. package/src/server.ts +38 -47
  70. package/src/stdio.ts +4 -3
  71. package/src/types.ts +12 -4
  72. package/src/util.ts +25 -0
  73. package/stdio.d.mts +2 -1
  74. package/stdio.d.mts.map +1 -1
  75. package/stdio.d.ts +2 -1
  76. package/stdio.d.ts.map +1 -1
  77. package/stdio.js +3 -3
  78. package/stdio.js.map +1 -1
  79. package/stdio.mjs +3 -3
  80. package/stdio.mjs.map +1 -1
  81. package/types.d.mts +8 -1
  82. package/types.d.mts.map +1 -1
  83. package/types.d.ts +8 -1
  84. package/types.d.ts.map +1 -1
  85. package/types.js.map +1 -1
  86. package/types.mjs.map +1 -1
  87. package/util.d.mts +4 -0
  88. package/util.d.mts.map +1 -0
  89. package/util.d.ts +4 -0
  90. package/util.d.ts.map +1 -0
  91. package/util.js +30 -0
  92. package/util.js.map +1 -0
  93. package/util.mjs +24 -0
  94. package/util.mjs.map +1 -0
  95. package/headers.d.mts +0 -4
  96. package/headers.d.mts.map +0 -1
  97. package/headers.d.ts +0 -4
  98. package/headers.d.ts.map +0 -1
  99. package/headers.js.map +0 -1
  100. package/headers.mjs.map +0 -1
package/server.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAs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MAAM,EAAE,CAAC,CAAC;gBAClD,MAAM;YACR,KAAK,OAAO;gBACV,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;gBACnD,MAAM;YACR;gBACE,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;gBACjD,MAAM;QACV,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAoB;IAC9C,MAAM,aAAa,GAAG;QACpB,QAAQ,CAAC;YACP,cAAc,EAAE,yBAAyB,CAAC,OAAO,CAAC;SACnD,CAAC;KACH,CAAC;IACF,IAAI,OAAO,EAAE,gBAAgB,IAAI,IAAI,EAAE,CAAC;QACtC,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,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"}
@@ -2,8 +2,9 @@
2
2
 
3
3
  import { IncomingMessage } from 'node:http';
4
4
  import { ClientOptions } from '@llamaindex/llama-cloud';
5
+ import { McpOptions } from './options';
5
6
 
6
- export const parseAuthHeaders = (req: IncomingMessage, required?: boolean): Partial<ClientOptions> => {
7
+ export const parseClientAuthHeaders = (req: IncomingMessage, required?: boolean): Partial<ClientOptions> => {
7
8
  if (req.headers.authorization) {
8
9
  const scheme = req.headers.authorization.split(' ')[0]!;
9
10
  const value = req.headers.authorization.slice(scheme.length + 1);
@@ -25,3 +26,17 @@ export const parseAuthHeaders = (req: IncomingMessage, required?: boolean): Part
25
26
  : req.headers['x-llama-cloud-api-key'];
26
27
  return { apiKey };
27
28
  };
29
+
30
+ export const getStainlessApiKey = (req: IncomingMessage, mcpOptions: McpOptions): string | undefined => {
31
+ // Try to get the key from the x-stainless-api-key header
32
+ const headerKey =
33
+ Array.isArray(req.headers['x-stainless-api-key']) ?
34
+ req.headers['x-stainless-api-key'][0]
35
+ : req.headers['x-stainless-api-key'];
36
+ if (headerKey && typeof headerKey === 'string') {
37
+ return headerKey;
38
+ }
39
+
40
+ // Fall back to value set in the mcpOptions (e.g. from environment variable), if provided
41
+ return mcpOptions.stainlessApiKey;
42
+ };
package/src/code-tool.ts CHANGED
@@ -1,10 +1,17 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { McpTool, Metadata, ToolCallResult, asErrorResult, asTextContentResult } from './types';
3
+ import {
4
+ McpRequestContext,
5
+ McpTool,
6
+ Metadata,
7
+ ToolCallResult,
8
+ asErrorResult,
9
+ asTextContentResult,
10
+ } from './types';
4
11
  import { Tool } from '@modelcontextprotocol/sdk/types.js';
5
- import { readEnv, requireValue } from './server';
12
+ import { readEnv, requireValue } from './util';
6
13
  import { WorkerInput, WorkerOutput } from './code-tool-types';
7
- import { LlamaCloud } from '@llamaindex/llama-cloud';
14
+ import { SdkMethod } from './methods';
8
15
 
9
16
  const prompt = `Runs JavaScript code to interact with the Llama Cloud API.
10
17
 
@@ -39,7 +46,7 @@ Variables will not persist between calls, so make sure to return or log any data
39
46
  *
40
47
  * @param endpoints - The endpoints to include in the list.
41
48
  */
42
- export function codeTool(): McpTool {
49
+ export function codeTool({ blockedMethods }: { blockedMethods: SdkMethod[] | undefined }): McpTool {
43
50
  const metadata: Metadata = { resource: 'all', operation: 'write', tags: [] };
44
51
  const tool: Tool = {
45
52
  name: 'execute',
@@ -59,20 +66,41 @@ export function codeTool(): McpTool {
59
66
  required: ['code'],
60
67
  },
61
68
  };
62
- const handler = async (client: LlamaCloud, args: any): Promise<ToolCallResult> => {
69
+ const handler = async ({
70
+ reqContext,
71
+ args,
72
+ }: {
73
+ reqContext: McpRequestContext;
74
+ args: any;
75
+ }): Promise<ToolCallResult> => {
63
76
  const code = args.code as string;
64
77
  const intent = args.intent as string | undefined;
78
+ const client = reqContext.client;
79
+
80
+ // Do very basic blocking of code that includes forbidden method names.
81
+ //
82
+ // WARNING: This is not secure against obfuscation and other evasion methods. If
83
+ // stronger security blocks are required, then these should be enforced in the downstream
84
+ // API (e.g., by having users call the MCP server with API keys with limited permissions).
85
+ if (blockedMethods) {
86
+ const blockedMatches = blockedMethods.filter((method) => code.includes(method.fullyQualifiedName));
87
+ if (blockedMatches.length > 0) {
88
+ return asErrorResult(
89
+ `The following methods have been blocked by the MCP server and cannot be used in code execution: ${blockedMatches
90
+ .map((m) => m.fullyQualifiedName)
91
+ .join(', ')}`,
92
+ );
93
+ }
94
+ }
65
95
 
66
- // this is not required, but passing a Stainless API key for the matching project_name
67
- // will allow you to run code-mode queries against non-published versions of your SDK.
68
- const stainlessAPIKey = readEnv('STAINLESS_API_KEY');
69
96
  const codeModeEndpoint =
70
97
  readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
71
98
 
99
+ // Setting a Stainless API key authenticates requests to the code tool endpoint.
72
100
  const res = await fetch(codeModeEndpoint, {
73
101
  method: 'POST',
74
102
  headers: {
75
- ...(stainlessAPIKey && { Authorization: stainlessAPIKey }),
103
+ ...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
76
104
  'Content-Type': 'application/json',
77
105
  client_envs: JSON.stringify({
78
106
  LLAMA_CLOUD_API_KEY: requireValue(
@@ -1,7 +1,6 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { Metadata, asTextContentResult } from './types';
4
-
3
+ import { Metadata, McpRequestContext, asTextContentResult } from './types';
5
4
  import { Tool } from '@modelcontextprotocol/sdk/types.js';
6
5
 
7
6
  export const metadata: Metadata = {
@@ -42,10 +41,20 @@ export const tool: Tool = {
42
41
  const docsSearchURL =
43
42
  process.env['DOCS_SEARCH_URL'] || 'https://api.stainless.com/api/projects/llamacloud-prod/docs/search';
44
43
 
45
- export const handler = async (_: unknown, args: Record<string, unknown> | undefined) => {
44
+ export const handler = async ({
45
+ reqContext,
46
+ args,
47
+ }: {
48
+ reqContext: McpRequestContext;
49
+ args: Record<string, unknown> | undefined;
50
+ }) => {
46
51
  const body = args as any;
47
52
  const query = new URLSearchParams(body).toString();
48
- const result = await fetch(`${docsSearchURL}?${query}`);
53
+ const result = await fetch(`${docsSearchURL}?${query}`, {
54
+ headers: {
55
+ ...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
56
+ },
57
+ });
49
58
 
50
59
  if (!result.ok) {
51
60
  throw new Error(
package/src/http.ts CHANGED
@@ -2,32 +2,39 @@
2
2
 
3
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
4
4
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
5
+ import { ClientOptions } from '@llamaindex/llama-cloud';
5
6
  import express from 'express';
6
7
  import morgan from 'morgan';
7
8
  import morganBody from 'morgan-body';
9
+ import { getStainlessApiKey, parseClientAuthHeaders } from './auth';
8
10
  import { McpOptions } from './options';
9
- import { ClientOptions, initMcpServer, newMcpServer } from './server';
10
- import { parseAuthHeaders } from './headers';
11
+ import { initMcpServer, newMcpServer } from './server';
11
12
 
12
13
  const newServer = async ({
13
14
  clientOptions,
15
+ mcpOptions,
14
16
  req,
15
17
  res,
16
18
  }: {
17
19
  clientOptions: ClientOptions;
20
+ mcpOptions: McpOptions;
18
21
  req: express.Request;
19
22
  res: express.Response;
20
23
  }): Promise<McpServer | null> => {
21
- const server = await newMcpServer();
24
+ const stainlessApiKey = getStainlessApiKey(req, mcpOptions);
25
+ const server = await newMcpServer(stainlessApiKey);
22
26
 
23
27
  try {
24
- const authOptions = parseAuthHeaders(req, false);
28
+ const authOptions = parseClientAuthHeaders(req, false);
29
+
25
30
  await initMcpServer({
26
31
  server: server,
32
+ mcpOptions: mcpOptions,
27
33
  clientOptions: {
28
34
  ...clientOptions,
29
35
  ...authOptions,
30
36
  },
37
+ stainlessApiKey: stainlessApiKey,
31
38
  });
32
39
  } catch (error) {
33
40
  res.status(401).json({
@@ -98,6 +105,9 @@ export const streamableHTTPApp = ({
98
105
  app.use(morgan('combined'));
99
106
  }
100
107
 
108
+ app.get('/health', async (req: express.Request, res: express.Response) => {
109
+ res.status(200).send('OK');
110
+ });
101
111
  app.get('/', get);
102
112
  app.post('/', post({ clientOptions, mcpOptions }));
103
113
  app.delete('/', del);
@@ -105,13 +115,17 @@ export const streamableHTTPApp = ({
105
115
  return app;
106
116
  };
107
117
 
108
- export const launchStreamableHTTPServer = async (params: {
118
+ export const launchStreamableHTTPServer = async ({
119
+ mcpOptions,
120
+ debug,
121
+ port,
122
+ }: {
109
123
  mcpOptions: McpOptions;
110
124
  debug: boolean;
111
125
  port: number | string | undefined;
112
126
  }) => {
113
- const app = streamableHTTPApp({ mcpOptions: params.mcpOptions, debug: params.debug });
114
- const server = app.listen(params.port);
127
+ const app = streamableHTTPApp({ mcpOptions, debug });
128
+ const server = app.listen(port);
115
129
  const address = server.address();
116
130
 
117
131
  if (typeof address === 'string') {
@@ -119,6 +133,6 @@ export const launchStreamableHTTPServer = async (params: {
119
133
  } else if (address !== null) {
120
134
  console.error(`MCP Server running on streamable HTTP on port ${address.port}`);
121
135
  } else {
122
- console.error(`MCP Server running on streamable HTTP on port ${params.port}`);
136
+ console.error(`MCP Server running on streamable HTTP on port ${port}`);
123
137
  }
124
138
  };
package/src/index.ts CHANGED
@@ -18,7 +18,7 @@ async function main() {
18
18
 
19
19
  switch (options.transport) {
20
20
  case 'stdio':
21
- await launchStdioServer();
21
+ await launchStdioServer(options);
22
22
  break;
23
23
  case 'http':
24
24
  await launchStreamableHTTPServer({