@pairdraw/mcp 0.16.2 → 0.17.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/dist/server.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { l as fail, n as startServer, o as MCP_AGENT_KINDS, s as registerTools, t as MCP_VERSION, u as ok } from "./server-Byl3Tcf4.mjs";
1
+ import { l as fail, n as startServer, o as MCP_AGENT_KINDS, s as registerTools, t as MCP_VERSION, u as ok } from "./server-B-NBTb6z.mjs";
2
2
  export { MCP_AGENT_KINDS, MCP_VERSION, fail, ok, registerTools, startServer };
package/dist/stdio.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import "./rolldown-runtime-ClRpJifh.mjs";
3
- import { a as createServerInstructions, c as registerSkill, s as registerTools, t as MCP_VERSION } from "./server-Byl3Tcf4.mjs";
3
+ import { a as createServerInstructions, c as registerSkill, s as registerTools, t as MCP_VERSION } from "./server-B-NBTb6z.mjs";
4
4
  import { a as getSocketPath, o as platformHasUnixSockets } from "./paths-BpcXnrbP.mjs";
5
5
  import { t as resolveMCPRoot } from "./root-BzmoiT2g.mjs";
6
6
  import { r as parseDisabledTools } from "./policy-B8Ka4WRH.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pairdraw/mcp",
3
- "version": "0.16.2",
3
+ "version": "0.17.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "@hono/node-server": "^1.19.17",
17
17
  "@modelcontextprotocol/server": "^2.0.0",
18
- "@pairdraw/core": "^0.16.2",
18
+ "@pairdraw/core": "^0.17.0",
19
19
  "@valibot/to-json-schema": "^1.8.0",
20
20
  "es-toolkit": "^1.52.0",
21
21
  "hono": "^4.13.13",
@@ -1,5 +1,25 @@
1
+ import { bodyLimit } from 'hono/body-limit'
2
+
3
+ import { MAX_FILE_TRANSFER_BYTES } from '#mcp/tool/output'
4
+
1
5
  export const MCP_CORS_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']
2
6
 
7
+ /**
8
+ * The largest body `/rpc` and `/mcp` read. Tool arguments carry files inline as Base64, such as
9
+ * `set_image_fill`'s `image_data`, so a file as large as `/files` passes still fits, with room
10
+ * for the rest of the request.
11
+ */
12
+ export const MAX_REQUEST_BODY_BYTES = 2 * MAX_FILE_TRANSFER_BYTES
13
+
14
+ /**
15
+ * Refuses a larger body, counted as it streams in, so one without Content-Length is bounded too.
16
+ * Routes check the token before it, so a caller without one never makes the server buffer.
17
+ */
18
+ export const limitBody = bodyLimit({
19
+ maxSize: MAX_REQUEST_BODY_BYTES,
20
+ onError: (c) => c.json({ error: 'Request is too large' }, 413)
21
+ })
22
+
3
23
  // x-mcp-token: Pairdraw extension for MCP clients that cannot set the
4
24
  // Authorization header (e.g. some IDE plugins). Not part of the MCP spec.
5
25
  export const MCP_CORS_HEADERS = [
package/src/server.ts CHANGED
@@ -12,7 +12,7 @@ import { MCP_AGENT_HEADER, MCP_CHAT_HEADER } from '@pairdraw/core/constants'
12
12
  import { createAgentBridge, type AgentBridge, type AgentBridgeOptions } from '#mcp/agents/index'
13
13
  import { bearerToken, isAuthorized, mcpRequestToken } from '#mcp/auth'
14
14
  import { createBrowserRPCBridge } from '#mcp/browser-rpc'
15
- import { MCP_CORS_HEADERS, MCP_CORS_METHODS, MCP_EXPOSED_HEADERS } from '#mcp/http-options'
15
+ import * as httpOptions from '#mcp/http-options'
16
16
  import type { RPCJSONObject } from '#mcp/json'
17
17
  import { registerFileRoutes } from '#mcp/server/files'
18
18
  import { createMCPSessionManager, sessionOpener } from '#mcp/server/sessions'
@@ -151,9 +151,9 @@ function createHonoApp(options: {
151
151
  '*',
152
152
  cors({
153
153
  origin: [...corsOrigins],
154
- allowMethods: MCP_CORS_METHODS,
155
- allowHeaders: MCP_CORS_HEADERS,
156
- exposeHeaders: MCP_EXPOSED_HEADERS
154
+ allowMethods: httpOptions.MCP_CORS_METHODS,
155
+ allowHeaders: httpOptions.MCP_CORS_HEADERS,
156
+ exposeHeaders: httpOptions.MCP_EXPOSED_HEADERS
157
157
  })
158
158
  )
159
159
  }
@@ -189,7 +189,7 @@ function createHonoApp(options: {
189
189
  }
190
190
 
191
191
  // Errors from sendToBrowser surface as 502, including a disconnected app (formerly 503).
192
- app.post('/rpc', async (c) => {
192
+ app.post('/rpc', httpOptions.limitBody, async (c) => {
193
193
  const body = await c.req.json().catch(() => null)
194
194
  if (!body || typeof body !== 'object' || Array.isArray(body)) {
195
195
  return c.json({ error: 'Invalid request body' }, 400)
@@ -203,11 +203,12 @@ function createHonoApp(options: {
203
203
  }
204
204
  })
205
205
 
206
- app.all('/mcp', async (c) => {
206
+ const requireMCPToken = async (c: Context, next: Next) => {
207
207
  const token = mcpRequestToken(c.req.header('authorization'), c.req.header('x-mcp-token'))
208
- if (!verifyMCPToken(token)) {
209
- return c.json({ error: 'Unauthorized' }, 401)
210
- }
208
+ return verifyMCPToken(token) ? next() : c.json({ error: 'Unauthorized' }, 401)
209
+ }
210
+
211
+ app.all('/mcp', requireMCPToken, httpOptions.limitBody, async (c) => {
211
212
  if (!MCP_METHODS.includes(c.req.method)) {
212
213
  return c.json(
213
214
  { error: 'Method not allowed' },