cas-parser-node-mcp 1.4.0 → 1.7.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 (215) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +29 -147
  3. package/auth.d.mts +4 -0
  4. package/auth.d.mts.map +1 -0
  5. package/auth.d.ts +4 -0
  6. package/auth.d.ts.map +1 -0
  7. package/{headers.js → auth.js} +2 -2
  8. package/auth.js.map +1 -0
  9. package/{headers.mjs → auth.mjs} +2 -2
  10. package/auth.mjs.map +1 -0
  11. package/code-tool-types.d.mts +7 -7
  12. package/code-tool-types.d.mts.map +1 -1
  13. package/code-tool-types.d.ts +7 -7
  14. package/code-tool-types.d.ts.map +1 -1
  15. package/code-tool.d.mts +6 -3
  16. package/code-tool.d.mts.map +1 -1
  17. package/code-tool.d.ts +6 -3
  18. package/code-tool.d.ts.map +1 -1
  19. package/code-tool.js +86 -132
  20. package/code-tool.js.map +1 -1
  21. package/code-tool.mjs +86 -99
  22. package/code-tool.mjs.map +1 -1
  23. package/{tools/cas-generator/generate-cas-cas-generator.d.ts → docs-search-tool.d.mts} +17 -11
  24. package/docs-search-tool.d.mts.map +1 -0
  25. package/{tools/cas-generator/generate-cas-cas-generator.d.mts → docs-search-tool.d.ts} +17 -11
  26. package/docs-search-tool.d.ts.map +1 -0
  27. package/docs-search-tool.js +57 -0
  28. package/docs-search-tool.js.map +1 -0
  29. package/docs-search-tool.mjs +53 -0
  30. package/docs-search-tool.mjs.map +1 -0
  31. package/http.d.mts +9 -4
  32. package/http.d.mts.map +1 -1
  33. package/http.d.ts +9 -4
  34. package/http.d.ts.map +1 -1
  35. package/http.js +31 -34
  36. package/http.js.map +1 -1
  37. package/http.mjs +31 -34
  38. package/http.mjs.map +1 -1
  39. package/index.js +8 -40
  40. package/index.js.map +1 -1
  41. package/index.mjs +8 -40
  42. package/index.mjs.map +1 -1
  43. package/methods.d.mts +10 -0
  44. package/methods.d.mts.map +1 -0
  45. package/methods.d.ts +10 -0
  46. package/methods.d.ts.map +1 -0
  47. package/methods.js +167 -0
  48. package/methods.js.map +1 -0
  49. package/methods.mjs +163 -0
  50. package/methods.mjs.map +1 -0
  51. package/options.d.mts +5 -9
  52. package/options.d.mts.map +1 -1
  53. package/options.d.ts +5 -9
  54. package/options.d.ts.map +1 -1
  55. package/options.js +37 -362
  56. package/options.js.map +1 -1
  57. package/options.mjs +37 -362
  58. package/options.mjs.map +1 -1
  59. package/package.json +57 -79
  60. package/server.d.mts +5 -15
  61. package/server.d.mts.map +1 -1
  62. package/server.d.ts +5 -15
  63. package/server.d.ts.map +1 -1
  64. package/server.js +54 -87
  65. package/server.js.map +1 -1
  66. package/server.mjs +53 -82
  67. package/server.mjs.map +1 -1
  68. package/src/{headers.ts → auth.ts} +1 -1
  69. package/src/code-tool-types.ts +7 -5
  70. package/src/code-tool.ts +104 -117
  71. package/src/docs-search-tool.ts +65 -0
  72. package/src/http.ts +44 -40
  73. package/src/index.ts +9 -52
  74. package/src/methods.ts +188 -0
  75. package/src/options.ts +48 -384
  76. package/src/server.ts +63 -97
  77. package/src/stdio.ts +4 -4
  78. package/src/{tools/types.ts → types.ts} +13 -1
  79. package/src/util.ts +25 -0
  80. package/stdio.d.mts +1 -1
  81. package/stdio.d.mts.map +1 -1
  82. package/stdio.d.ts +1 -1
  83. package/stdio.d.ts.map +1 -1
  84. package/stdio.js +3 -3
  85. package/stdio.js.map +1 -1
  86. package/stdio.mjs +3 -3
  87. package/stdio.mjs.map +1 -1
  88. package/{tools/types.d.mts → types.d.mts} +2 -1
  89. package/types.d.mts.map +1 -0
  90. package/{tools/types.d.ts → types.d.ts} +2 -1
  91. package/types.d.ts.map +1 -0
  92. package/{tools/types.js → types.js} +12 -0
  93. package/types.js.map +1 -0
  94. package/{tools/types.mjs → types.mjs} +11 -0
  95. package/types.mjs.map +1 -0
  96. package/util.d.mts +4 -0
  97. package/util.d.mts.map +1 -0
  98. package/util.d.ts +4 -0
  99. package/util.d.ts.map +1 -0
  100. package/util.js +30 -0
  101. package/util.js.map +1 -0
  102. package/util.mjs +24 -0
  103. package/util.mjs.map +1 -0
  104. package/code-tool-paths.cjs +0 -6
  105. package/code-tool-paths.cjs.map +0 -1
  106. package/code-tool-paths.d.cts +0 -2
  107. package/code-tool-paths.d.cts.map +0 -1
  108. package/code-tool-worker.d.mts +0 -5
  109. package/code-tool-worker.d.mts.map +0 -1
  110. package/code-tool-worker.d.ts +0 -5
  111. package/code-tool-worker.d.ts.map +0 -1
  112. package/code-tool-worker.js +0 -45
  113. package/code-tool-worker.js.map +0 -1
  114. package/code-tool-worker.mjs +0 -40
  115. package/code-tool-worker.mjs.map +0 -1
  116. package/compat.d.mts +0 -58
  117. package/compat.d.mts.map +0 -1
  118. package/compat.d.ts +0 -58
  119. package/compat.d.ts.map +0 -1
  120. package/compat.js +0 -387
  121. package/compat.js.map +0 -1
  122. package/compat.mjs +0 -378
  123. package/compat.mjs.map +0 -1
  124. package/dynamic-tools.d.mts +0 -12
  125. package/dynamic-tools.d.mts.map +0 -1
  126. package/dynamic-tools.d.ts +0 -12
  127. package/dynamic-tools.d.ts.map +0 -1
  128. package/dynamic-tools.js +0 -135
  129. package/dynamic-tools.js.map +0 -1
  130. package/dynamic-tools.mjs +0 -132
  131. package/dynamic-tools.mjs.map +0 -1
  132. package/filtering.d.mts +0 -2
  133. package/filtering.d.mts.map +0 -1
  134. package/filtering.d.ts +0 -2
  135. package/filtering.d.ts.map +0 -1
  136. package/filtering.js +0 -20
  137. package/filtering.js.map +0 -1
  138. package/filtering.mjs +0 -13
  139. package/filtering.mjs.map +0 -1
  140. package/headers.d.mts +0 -4
  141. package/headers.d.mts.map +0 -1
  142. package/headers.d.ts +0 -4
  143. package/headers.d.ts.map +0 -1
  144. package/headers.js.map +0 -1
  145. package/headers.mjs.map +0 -1
  146. package/src/code-tool-paths.cts +0 -3
  147. package/src/code-tool-worker.ts +0 -46
  148. package/src/compat.ts +0 -483
  149. package/src/dynamic-tools.ts +0 -159
  150. package/src/filtering.ts +0 -14
  151. package/src/tools/cas-generator/generate-cas-cas-generator.ts +0 -67
  152. package/src/tools/cas-parser/cams-kfintech-cas-parser.ts +0 -47
  153. package/src/tools/cas-parser/cdsl-cas-parser.ts +0 -47
  154. package/src/tools/cas-parser/nsdl-cas-parser.ts +0 -47
  155. package/src/tools/cas-parser/smart-parse-cas-parser.ts +0 -47
  156. package/src/tools/index.ts +0 -79
  157. package/src/tools.ts +0 -1
  158. package/tools/cas-generator/generate-cas-cas-generator.d.mts.map +0 -1
  159. package/tools/cas-generator/generate-cas-cas-generator.d.ts.map +0 -1
  160. package/tools/cas-generator/generate-cas-cas-generator.js +0 -62
  161. package/tools/cas-generator/generate-cas-cas-generator.js.map +0 -1
  162. package/tools/cas-generator/generate-cas-cas-generator.mjs +0 -58
  163. package/tools/cas-generator/generate-cas-cas-generator.mjs.map +0 -1
  164. package/tools/cas-parser/cams-kfintech-cas-parser.d.mts +0 -45
  165. package/tools/cas-parser/cams-kfintech-cas-parser.d.mts.map +0 -1
  166. package/tools/cas-parser/cams-kfintech-cas-parser.d.ts +0 -45
  167. package/tools/cas-parser/cams-kfintech-cas-parser.d.ts.map +0 -1
  168. package/tools/cas-parser/cams-kfintech-cas-parser.js +0 -43
  169. package/tools/cas-parser/cams-kfintech-cas-parser.js.map +0 -1
  170. package/tools/cas-parser/cams-kfintech-cas-parser.mjs +0 -39
  171. package/tools/cas-parser/cams-kfintech-cas-parser.mjs.map +0 -1
  172. package/tools/cas-parser/cdsl-cas-parser.d.mts +0 -45
  173. package/tools/cas-parser/cdsl-cas-parser.d.mts.map +0 -1
  174. package/tools/cas-parser/cdsl-cas-parser.d.ts +0 -45
  175. package/tools/cas-parser/cdsl-cas-parser.d.ts.map +0 -1
  176. package/tools/cas-parser/cdsl-cas-parser.js +0 -43
  177. package/tools/cas-parser/cdsl-cas-parser.js.map +0 -1
  178. package/tools/cas-parser/cdsl-cas-parser.mjs +0 -39
  179. package/tools/cas-parser/cdsl-cas-parser.mjs.map +0 -1
  180. package/tools/cas-parser/nsdl-cas-parser.d.mts +0 -45
  181. package/tools/cas-parser/nsdl-cas-parser.d.mts.map +0 -1
  182. package/tools/cas-parser/nsdl-cas-parser.d.ts +0 -45
  183. package/tools/cas-parser/nsdl-cas-parser.d.ts.map +0 -1
  184. package/tools/cas-parser/nsdl-cas-parser.js +0 -43
  185. package/tools/cas-parser/nsdl-cas-parser.js.map +0 -1
  186. package/tools/cas-parser/nsdl-cas-parser.mjs +0 -39
  187. package/tools/cas-parser/nsdl-cas-parser.mjs.map +0 -1
  188. package/tools/cas-parser/smart-parse-cas-parser.d.mts +0 -45
  189. package/tools/cas-parser/smart-parse-cas-parser.d.mts.map +0 -1
  190. package/tools/cas-parser/smart-parse-cas-parser.d.ts +0 -45
  191. package/tools/cas-parser/smart-parse-cas-parser.d.ts.map +0 -1
  192. package/tools/cas-parser/smart-parse-cas-parser.js +0 -43
  193. package/tools/cas-parser/smart-parse-cas-parser.js.map +0 -1
  194. package/tools/cas-parser/smart-parse-cas-parser.mjs +0 -39
  195. package/tools/cas-parser/smart-parse-cas-parser.mjs.map +0 -1
  196. package/tools/index.d.mts +0 -10
  197. package/tools/index.d.mts.map +0 -1
  198. package/tools/index.d.ts +0 -10
  199. package/tools/index.d.ts.map +0 -1
  200. package/tools/index.js +0 -63
  201. package/tools/index.js.map +0 -1
  202. package/tools/index.mjs +0 -56
  203. package/tools/index.mjs.map +0 -1
  204. package/tools/types.d.mts.map +0 -1
  205. package/tools/types.d.ts.map +0 -1
  206. package/tools/types.js.map +0 -1
  207. package/tools/types.mjs.map +0 -1
  208. package/tools.d.mts +0 -2
  209. package/tools.d.mts.map +0 -1
  210. package/tools.d.ts +0 -2
  211. package/tools.d.ts.map +0 -1
  212. package/tools.js +0 -18
  213. package/tools.js.map +0 -1
  214. package/tools.mjs +0 -2
  215. package/tools.mjs.map +0 -1
package/src/http.ts CHANGED
@@ -2,16 +2,17 @@
2
2
 
3
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
4
4
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
5
-
5
+ import { ClientOptions } from 'cas-parser-node';
6
6
  import express from 'express';
7
- import { fromError } from 'zod-validation-error/v3';
8
- import { McpOptions, parseQueryOptions } from './options';
9
- import { ClientOptions, initMcpServer, newMcpServer } from './server';
10
- import { parseAuthHeaders } from './headers';
7
+ import morgan from 'morgan';
8
+ import morganBody from 'morgan-body';
9
+ import { parseAuthHeaders } from './auth';
10
+ import { McpOptions } from './options';
11
+ import { initMcpServer, newMcpServer } from './server';
11
12
 
12
- const newServer = ({
13
+ const newServer = async ({
13
14
  clientOptions,
14
- mcpOptions: defaultMcpOptions,
15
+ mcpOptions,
15
16
  req,
16
17
  res,
17
18
  }: {
@@ -19,39 +20,25 @@ const newServer = ({
19
20
  mcpOptions: McpOptions;
20
21
  req: express.Request;
21
22
  res: express.Response;
22
- }): McpServer | null => {
23
- const server = newMcpServer();
24
-
25
- let mcpOptions: McpOptions;
26
- try {
27
- mcpOptions = parseQueryOptions(defaultMcpOptions, req.query);
28
- } catch (error) {
29
- res.status(400).json({
30
- jsonrpc: '2.0',
31
- error: {
32
- code: -32000,
33
- message: `Invalid request: ${fromError(error)}`,
34
- },
35
- });
36
- return null;
37
- }
23
+ }): Promise<McpServer | null> => {
24
+ const server = await newMcpServer();
38
25
 
39
26
  try {
40
- const authOptions = parseAuthHeaders(req);
41
- initMcpServer({
27
+ const authOptions = parseAuthHeaders(req, false);
28
+ await initMcpServer({
42
29
  server: server,
30
+ mcpOptions: mcpOptions,
43
31
  clientOptions: {
44
32
  ...clientOptions,
45
33
  ...authOptions,
46
34
  },
47
- mcpOptions,
48
35
  });
49
- } catch {
36
+ } catch (error) {
50
37
  res.status(401).json({
51
38
  jsonrpc: '2.0',
52
39
  error: {
53
40
  code: -32000,
54
- message: 'Unauthorized',
41
+ message: `Unauthorized: ${error instanceof Error ? error.message : error}`,
55
42
  },
56
43
  });
57
44
  return null;
@@ -63,14 +50,11 @@ const newServer = ({
63
50
  const post =
64
51
  (options: { clientOptions: ClientOptions; mcpOptions: McpOptions }) =>
65
52
  async (req: express.Request, res: express.Response) => {
66
- const server = newServer({ ...options, req, res });
53
+ const server = await newServer({ ...options, req, res });
67
54
  // If we return null, we already set the authorization error.
68
55
  if (server === null) return;
69
- const transport = new StreamableHTTPServerTransport({
70
- // Stateless server
71
- sessionIdGenerator: undefined,
72
- });
73
- await server.connect(transport);
56
+ const transport = new StreamableHTTPServerTransport();
57
+ await server.connect(transport as any);
74
58
  await transport.handleRequest(req, res, req.body);
75
59
  };
76
60
 
@@ -96,15 +80,31 @@ const del = async (req: express.Request, res: express.Response) => {
96
80
 
97
81
  export const streamableHTTPApp = ({
98
82
  clientOptions = {},
99
- mcpOptions = {},
83
+ mcpOptions,
84
+ debug,
100
85
  }: {
101
86
  clientOptions?: ClientOptions;
102
- mcpOptions?: McpOptions;
87
+ mcpOptions: McpOptions;
88
+ debug: boolean;
103
89
  }): express.Express => {
104
90
  const app = express();
105
91
  app.set('query parser', 'extended');
106
92
  app.use(express.json());
107
93
 
94
+ if (debug) {
95
+ morganBody(app, {
96
+ logAllReqHeader: true,
97
+ logAllResHeader: true,
98
+ logRequestBody: true,
99
+ logResponseBody: true,
100
+ });
101
+ } else {
102
+ app.use(morgan('combined'));
103
+ }
104
+
105
+ app.get('/health', async (req: express.Request, res: express.Response) => {
106
+ res.status(200).send('OK');
107
+ });
108
108
  app.get('/', get);
109
109
  app.post('/', post({ clientOptions, mcpOptions }));
110
110
  app.delete('/', del);
@@ -112,9 +112,13 @@ export const streamableHTTPApp = ({
112
112
  return app;
113
113
  };
114
114
 
115
- export const launchStreamableHTTPServer = async (options: McpOptions, port: number | string | undefined) => {
116
- const app = streamableHTTPApp({ mcpOptions: options });
117
- const server = app.listen(port);
115
+ export const launchStreamableHTTPServer = async (params: {
116
+ mcpOptions: McpOptions;
117
+ debug: boolean;
118
+ port: number | string | undefined;
119
+ }) => {
120
+ const app = streamableHTTPApp({ mcpOptions: params.mcpOptions, debug: params.debug });
121
+ const server = app.listen(params.port);
118
122
  const address = server.address();
119
123
 
120
124
  if (typeof address === 'string') {
@@ -122,6 +126,6 @@ export const launchStreamableHTTPServer = async (options: McpOptions, port: numb
122
126
  } else if (address !== null) {
123
127
  console.error(`MCP Server running on streamable HTTP on port ${address.port}`);
124
128
  } else {
125
- console.error(`MCP Server running on streamable HTTP on port ${port}`);
129
+ console.error(`MCP Server running on streamable HTTP on port ${params.port}`);
126
130
  }
127
131
  };
package/src/index.ts CHANGED
@@ -1,20 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { selectTools } from './server';
4
- import { Endpoint, endpoints } from './tools';
5
4
  import { McpOptions, parseCLIOptions } from './options';
6
5
  import { launchStdioServer } from './stdio';
7
6
  import { launchStreamableHTTPServer } from './http';
7
+ import type { McpTool } from './types';
8
8
 
9
9
  async function main() {
10
10
  const options = parseOptionsOrError();
11
11
 
12
- if (options.list) {
13
- listAllTools();
14
- return;
15
- }
16
-
17
- const selectedTools = await selectToolsOrError(endpoints, options);
12
+ const selectedTools = await selectToolsOrError(options);
18
13
 
19
14
  console.error(
20
15
  `MCP Server starting with ${selectedTools.length} tools:`,
@@ -26,7 +21,11 @@ async function main() {
26
21
  await launchStdioServer(options);
27
22
  break;
28
23
  case 'http':
29
- await launchStreamableHTTPServer(options, options.port ?? options.socket);
24
+ await launchStreamableHTTPServer({
25
+ mcpOptions: options,
26
+ debug: options.debug,
27
+ port: options.port ?? options.socket,
28
+ });
30
29
  break;
31
30
  }
32
31
  }
@@ -47,9 +46,9 @@ function parseOptionsOrError() {
47
46
  }
48
47
  }
49
48
 
50
- async function selectToolsOrError(endpoints: Endpoint[], options: McpOptions): Promise<Endpoint[]> {
49
+ async function selectToolsOrError(options: McpOptions): Promise<McpTool[]> {
51
50
  try {
52
- const includedTools = await selectTools(endpoints, options);
51
+ const includedTools = selectTools(options);
53
52
  if (includedTools.length === 0) {
54
53
  console.error('No tools match the provided filters.');
55
54
  process.exit(1);
@@ -64,45 +63,3 @@ async function selectToolsOrError(endpoints: Endpoint[], options: McpOptions): P
64
63
  process.exit(1);
65
64
  }
66
65
  }
67
-
68
- function listAllTools() {
69
- if (endpoints.length === 0) {
70
- console.log('No tools available.');
71
- return;
72
- }
73
- console.log('Available tools:\n');
74
-
75
- // Group endpoints by resource
76
- const resourceGroups = new Map<string, typeof endpoints>();
77
-
78
- for (const endpoint of endpoints) {
79
- const resource = endpoint.metadata.resource;
80
- if (!resourceGroups.has(resource)) {
81
- resourceGroups.set(resource, []);
82
- }
83
- resourceGroups.get(resource)!.push(endpoint);
84
- }
85
-
86
- // Sort resources alphabetically
87
- const sortedResources = Array.from(resourceGroups.keys()).sort();
88
-
89
- // Display hierarchically by resource
90
- for (const resource of sortedResources) {
91
- console.log(`Resource: ${resource}`);
92
-
93
- const resourceEndpoints = resourceGroups.get(resource)!;
94
- // Sort endpoints by tool name
95
- resourceEndpoints.sort((a, b) => a.tool.name.localeCompare(b.tool.name));
96
-
97
- for (const endpoint of resourceEndpoints) {
98
- const {
99
- tool,
100
- metadata: { operation, tags },
101
- } = endpoint;
102
-
103
- console.log(` - ${tool.name} (${operation}) ${tags.length > 0 ? `tags: ${tags.join(', ')}` : ''}`);
104
- console.log(` Description: ${tool.description}`);
105
- }
106
- console.log('');
107
- }
108
- }
package/src/methods.ts ADDED
@@ -0,0 +1,188 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { McpOptions } from './options';
4
+
5
+ export type SdkMethod = {
6
+ clientCallName: string;
7
+ fullyQualifiedName: string;
8
+ httpMethod?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'query';
9
+ httpPath?: string;
10
+ };
11
+
12
+ export const sdkMethods: SdkMethod[] = [
13
+ {
14
+ clientCallName: 'client.credits.check',
15
+ fullyQualifiedName: 'credits.check',
16
+ httpMethod: 'post',
17
+ httpPath: '/credits',
18
+ },
19
+ {
20
+ clientCallName: 'client.logs.create',
21
+ fullyQualifiedName: 'logs.create',
22
+ httpMethod: 'post',
23
+ httpPath: '/logs',
24
+ },
25
+ {
26
+ clientCallName: 'client.logs.getSummary',
27
+ fullyQualifiedName: 'logs.getSummary',
28
+ httpMethod: 'post',
29
+ httpPath: '/logs/summary',
30
+ },
31
+ {
32
+ clientCallName: 'client.accessToken.create',
33
+ fullyQualifiedName: 'accessToken.create',
34
+ httpMethod: 'post',
35
+ httpPath: '/v1/access-token',
36
+ },
37
+ {
38
+ clientCallName: 'client.verifyToken.verify',
39
+ fullyQualifiedName: 'verifyToken.verify',
40
+ httpMethod: 'post',
41
+ httpPath: '/v1/verify-token',
42
+ },
43
+ {
44
+ clientCallName: 'client.camsKfintech.parse',
45
+ fullyQualifiedName: 'camsKfintech.parse',
46
+ httpMethod: 'post',
47
+ httpPath: '/v4/cams_kfintech/parse',
48
+ },
49
+ {
50
+ clientCallName: 'client.cdsl.parsePdf',
51
+ fullyQualifiedName: 'cdsl.parsePdf',
52
+ httpMethod: 'post',
53
+ httpPath: '/v4/cdsl/parse',
54
+ },
55
+ {
56
+ clientCallName: 'client.cdsl.fetch.requestOtp',
57
+ fullyQualifiedName: 'cdsl.fetch.requestOtp',
58
+ httpMethod: 'post',
59
+ httpPath: '/v4/cdsl/fetch',
60
+ },
61
+ {
62
+ clientCallName: 'client.cdsl.fetch.verifyOtp',
63
+ fullyQualifiedName: 'cdsl.fetch.verifyOtp',
64
+ httpMethod: 'post',
65
+ httpPath: '/v4/cdsl/fetch/{session_id}/verify',
66
+ },
67
+ {
68
+ clientCallName: 'client.contractNote.parse',
69
+ fullyQualifiedName: 'contractNote.parse',
70
+ httpMethod: 'post',
71
+ httpPath: '/v4/contract_note/parse',
72
+ },
73
+ {
74
+ clientCallName: 'client.inbox.checkConnectionStatus',
75
+ fullyQualifiedName: 'inbox.checkConnectionStatus',
76
+ httpMethod: 'post',
77
+ httpPath: '/v4/inbox/status',
78
+ },
79
+ {
80
+ clientCallName: 'client.inbox.connectEmail',
81
+ fullyQualifiedName: 'inbox.connectEmail',
82
+ httpMethod: 'post',
83
+ httpPath: '/v4/inbox/connect',
84
+ },
85
+ {
86
+ clientCallName: 'client.inbox.disconnectEmail',
87
+ fullyQualifiedName: 'inbox.disconnectEmail',
88
+ httpMethod: 'post',
89
+ httpPath: '/v4/inbox/disconnect',
90
+ },
91
+ {
92
+ clientCallName: 'client.inbox.listCasFiles',
93
+ fullyQualifiedName: 'inbox.listCasFiles',
94
+ httpMethod: 'post',
95
+ httpPath: '/v4/inbox/cas',
96
+ },
97
+ {
98
+ clientCallName: 'client.kfintech.generateCas',
99
+ fullyQualifiedName: 'kfintech.generateCas',
100
+ httpMethod: 'post',
101
+ httpPath: '/v4/kfintech/generate',
102
+ },
103
+ {
104
+ clientCallName: 'client.nsdl.parse',
105
+ fullyQualifiedName: 'nsdl.parse',
106
+ httpMethod: 'post',
107
+ httpPath: '/v4/nsdl/parse',
108
+ },
109
+ {
110
+ clientCallName: 'client.smart.parseCasPdf',
111
+ fullyQualifiedName: 'smart.parseCasPdf',
112
+ httpMethod: 'post',
113
+ httpPath: '/v4/smart/parse',
114
+ },
115
+ ];
116
+
117
+ function allowedMethodsForCodeTool(options: McpOptions | undefined): SdkMethod[] | undefined {
118
+ if (!options) {
119
+ return undefined;
120
+ }
121
+
122
+ let allowedMethods: SdkMethod[];
123
+
124
+ if (options.codeAllowHttpGets || options.codeAllowedMethods) {
125
+ // Start with nothing allowed and then add into it from options
126
+ let allowedMethodsSet = new Set<SdkMethod>();
127
+
128
+ if (options.codeAllowHttpGets) {
129
+ // Add all methods that map to an HTTP GET
130
+ sdkMethods
131
+ .filter((method) => method.httpMethod === 'get')
132
+ .forEach((method) => allowedMethodsSet.add(method));
133
+ }
134
+
135
+ if (options.codeAllowedMethods) {
136
+ // Add all methods that match any of the allowed regexps
137
+ const allowedRegexps = options.codeAllowedMethods.map((pattern) => {
138
+ try {
139
+ return new RegExp(pattern);
140
+ } catch (e) {
141
+ throw new Error(
142
+ `Invalid regex pattern for allowed method: "${pattern}": ${e instanceof Error ? e.message : e}`,
143
+ );
144
+ }
145
+ });
146
+
147
+ sdkMethods
148
+ .filter((method) => allowedRegexps.some((regexp) => regexp.test(method.fullyQualifiedName)))
149
+ .forEach((method) => allowedMethodsSet.add(method));
150
+ }
151
+
152
+ allowedMethods = Array.from(allowedMethodsSet);
153
+ } else {
154
+ // Start with everything allowed
155
+ allowedMethods = [...sdkMethods];
156
+ }
157
+
158
+ if (options.codeBlockedMethods) {
159
+ // Filter down based on blocked regexps
160
+ const blockedRegexps = options.codeBlockedMethods.map((pattern) => {
161
+ try {
162
+ return new RegExp(pattern);
163
+ } catch (e) {
164
+ throw new Error(
165
+ `Invalid regex pattern for blocked method: "${pattern}": ${e instanceof Error ? e.message : e}`,
166
+ );
167
+ }
168
+ });
169
+
170
+ allowedMethods = allowedMethods.filter(
171
+ (method) => !blockedRegexps.some((regexp) => regexp.test(method.fullyQualifiedName)),
172
+ );
173
+ }
174
+
175
+ return allowedMethods;
176
+ }
177
+
178
+ export function blockedMethodsForCodeTool(options: McpOptions | undefined): SdkMethod[] | undefined {
179
+ const allowedMethods = allowedMethodsForCodeTool(options);
180
+ if (!allowedMethods) {
181
+ return undefined;
182
+ }
183
+
184
+ const allowedSet = new Set(allowedMethods.map((method) => method.fullyQualifiedName));
185
+
186
+ // Return any methods that are not explicitly allowed
187
+ return sdkMethods.filter((method) => !allowedSet.has(method.fullyQualifiedName));
188
+ }