mcp-expose 1.1.0 → 1.1.2

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 (47) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.md +143 -34
  3. package/dist/adonisjs/index.cjs +128 -6
  4. package/dist/adonisjs/index.cjs.map +1 -1
  5. package/dist/adonisjs/index.d.cts +1 -1
  6. package/dist/adonisjs/index.d.ts +1 -1
  7. package/dist/adonisjs/index.js +128 -6
  8. package/dist/adonisjs/index.js.map +1 -1
  9. package/dist/express/index.cjs +128 -6
  10. package/dist/express/index.cjs.map +1 -1
  11. package/dist/express/index.d.cts +1 -1
  12. package/dist/express/index.d.ts +1 -1
  13. package/dist/express/index.js +128 -6
  14. package/dist/express/index.js.map +1 -1
  15. package/dist/fastify/index.cjs +128 -6
  16. package/dist/fastify/index.cjs.map +1 -1
  17. package/dist/fastify/index.d.cts +1 -1
  18. package/dist/fastify/index.d.ts +1 -1
  19. package/dist/fastify/index.js +128 -6
  20. package/dist/fastify/index.js.map +1 -1
  21. package/dist/hono/index.cjs +128 -6
  22. package/dist/hono/index.cjs.map +1 -1
  23. package/dist/hono/index.d.cts +1 -1
  24. package/dist/hono/index.d.ts +1 -1
  25. package/dist/hono/index.js +128 -6
  26. package/dist/hono/index.js.map +1 -1
  27. package/dist/index.cjs +128 -31
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +7 -5
  30. package/dist/index.d.ts +7 -5
  31. package/dist/index.js +128 -31
  32. package/dist/index.js.map +1 -1
  33. package/dist/koa/index.cjs +128 -6
  34. package/dist/koa/index.cjs.map +1 -1
  35. package/dist/koa/index.d.cts +1 -1
  36. package/dist/koa/index.d.ts +1 -1
  37. package/dist/koa/index.js +128 -6
  38. package/dist/koa/index.js.map +1 -1
  39. package/dist/nestjs/index.cjs +128 -6
  40. package/dist/nestjs/index.cjs.map +1 -1
  41. package/dist/nestjs/index.d.cts +1 -1
  42. package/dist/nestjs/index.d.ts +1 -1
  43. package/dist/nestjs/index.js +128 -6
  44. package/dist/nestjs/index.js.map +1 -1
  45. package/dist/{server-BFQ_Hdh9.d.cts → server--mQVQq3A.d.cts} +55 -2
  46. package/dist/{server-BRw1E2xy.d.ts → server-BPDTsT2o.d.ts} +55 -2
  47. package/package.json +2 -1
@@ -1,4 +1,4 @@
1
- import { O as OAuthOptions, A as AuthInfo } from './oauth-8RmQamGP.js';
1
+ import { A as AuthInfo, O as OAuthOptions } from './oauth-8RmQamGP.js';
2
2
 
3
3
  /**
4
4
  * Shared types for mcp-expose. Everything in `core` is runtime-agnostic
@@ -99,7 +99,55 @@ interface RouteToolOptions {
99
99
  headers?: Record<string, string>;
100
100
  /** OAuth scopes needed to call this tool (when the `oauth` option is enabled). */
101
101
  scopes?: string[];
102
+ /**
103
+ * Shape what the agent sees from the route's response: trim or rename fields,
104
+ * add hints, or enrich it with data from other routes (`ctx.callRoute`).
105
+ * Overrides the server-level `transformResponse`.
106
+ */
107
+ transformResponse?: ResponseTransform;
108
+ }
109
+ /** A route's HTTP response as seen by `transformResponse`. */
110
+ interface RouteToolResponse extends RouteResponse {
111
+ /** The parsed body when the response is JSON, otherwise `undefined`. */
112
+ json?: unknown;
113
+ /** `true` for 2xx/3xx responses. */
114
+ ok: boolean;
115
+ }
116
+ interface ResponseTransformContext {
117
+ /** Name of the tool being called. */
118
+ tool: string;
119
+ /** The arguments the agent passed (after validation). */
120
+ args: Record<string, unknown>;
121
+ /** The internal request that produced the response. */
122
+ request: RouteRequest;
123
+ /** The MCP call context: headers, client IP and, with OAuth, the verified token (`auth`). */
124
+ toolContext: ToolContext;
125
+ /** The result mcp-expose would return without the hook. */
126
+ defaultResult(): ToolResult;
127
+ /**
128
+ * Call another route of the same app, with the same forwarded credentials
129
+ * (auth header, cookies) and through the same middleware, guards and validation.
130
+ */
131
+ callRoute(request: {
132
+ method?: string;
133
+ /** Path of the route, e.g. `/customers/:id`. Placeholders are filled from `params`. */
134
+ path: string;
135
+ /** Values for `:param` / `{param}` placeholders; URL-encoded, and `.` / `..` are rejected. */
136
+ params?: Record<string, unknown>;
137
+ query?: Record<string, string | string[]>;
138
+ body?: unknown;
139
+ headers?: Record<string, string>;
140
+ }): Promise<RouteToolResponse>;
102
141
  }
142
+ /**
143
+ * Turns a route's response into the tool result. Return:
144
+ * - a string or any JSON value: sent to the agent (as `structuredContent` for objects).
145
+ * It is an error result when the route answered with an HTTP error status;
146
+ * - a full `ToolResult`: used as is (set `isError` yourself);
147
+ * - `undefined`: keep the default result.
148
+ * Throwing turns the call into an error result with the message.
149
+ */
150
+ type ResponseTransform = (response: RouteToolResponse, ctx: ResponseTransformContext) => unknown;
103
151
  /** HTTP route that backs a tool. `path` may use `:param` or `{param}` placeholders. */
104
152
  interface RouteSpec {
105
153
  method: string;
@@ -148,6 +196,11 @@ interface McpServerOptions {
148
196
  forwardHeaders?: string[];
149
197
  /** Max characters of an API response returned to the model. @default 100_000 */
150
198
  maxResponseChars?: number;
199
+ /**
200
+ * Default `transformResponse` for every route tool of this server that does not
201
+ * set its own (e.g. to strip internal fields everywhere).
202
+ */
203
+ transformResponse?: ResponseTransform;
151
204
  /**
152
205
  * Protect the MCP endpoint with OAuth 2.1, as the MCP authorization spec
153
206
  * describes. MCP clients (Claude, Cursor, VS Code, ...) then discover your
@@ -218,4 +271,4 @@ declare class McpServer {
218
271
  handleHttp(req: McpHttpRequest, ctx: ToolContext): Promise<McpHttpResponse>;
219
272
  }
220
273
 
221
- export { type Dispatcher as D, type JsonSchema as J, LATEST_PROTOCOL_VERSION as L, type McpServerOptions as M, type RouteToolOptions as R, type SchemaLike as S, type ToolContext as T, type McpToolDefinition as a, McpServer as b, type RouteSpec as c, type ToolAnnotations as d, type ToolResult as e, type JsonRpcResponse as f, type McpHttpRequest as g, type McpHttpResponse as h, type RouteRequest as i, type RouteResponse as j, SUPPORTED_PROTOCOL_VERSIONS as k, type TextContent as l };
274
+ export { type Dispatcher as D, type JsonSchema as J, LATEST_PROTOCOL_VERSION as L, type McpServerOptions as M, type RouteToolOptions as R, type SchemaLike as S, type ToolContext as T, type McpToolDefinition as a, McpServer as b, type RouteSpec as c, type ToolResult as d, type ToolAnnotations as e, type JsonRpcResponse as f, type McpHttpRequest as g, type McpHttpResponse as h, type ResponseTransform as i, type ResponseTransformContext as j, type RouteRequest as k, type RouteResponse as l, type RouteToolResponse as m, SUPPORTED_PROTOCOL_VERSIONS as n, type TextContent as o };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-expose",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Turn the HTTP routes of your existing Node.js app (NestJS, Express, Fastify, Koa, Hono, AdonisJS) into MCP tools for AI agents, reusing your auth, validation and rate limits.",
5
5
  "keywords": [
6
6
  "mcp",
@@ -220,6 +220,7 @@
220
220
  "class-validator": "^0.15.1",
221
221
  "eslint": "^10.11.0",
222
222
  "express": "^5.2.1",
223
+ "express-rate-limit": "^8.7.0",
223
224
  "fastify": "^5.12.5",
224
225
  "globals": "^17.12.0",
225
226
  "hono": "^4.13.9",