Skip to content

Commit dca7d8b

Browse files
valentinbeggiclaude
andcommitted
feat: add url property to RequestInfo interface
Expose the request URL in RequestInfo, allowing server handlers to access query parameters, path info, and other URL components from incoming requests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent f82c997 commit dca7d8b

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@modelcontextprotocol/core": minor
3+
"@modelcontextprotocol/server": minor
4+
---
5+
6+
Add `url` property to `RequestInfo` interface
7+
8+
The `RequestInfo` interface now includes an optional `url` property that exposes the URL of the incoming HTTP request. This enables server-side handlers to access query parameters, path information, and other URL components.
9+
10+
```typescript
11+
export interface RequestInfo {
12+
headers: IsomorphicHeaders;
13+
url?: string;
14+
}
15+
```

packages/core/src/types/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,10 @@ export interface RequestInfo {
23972397
* The headers of the request.
23982398
*/
23992399
headers: IsomorphicHeaders;
2400+
/**
2401+
* The URL of the request.
2402+
*/
2403+
url?: string;
24002404
}
24012405

24022406
/**

packages/server/src/server/sse.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ export class SSEServerTransport implements Transport {
149149
}
150150

151151
const authInfo: AuthInfo | undefined = req.auth;
152-
const requestInfo: RequestInfo = { headers: req.headers };
152+
const requestInfo: RequestInfo = {
153+
headers: req.headers,
154+
url: req.url
155+
};
153156

154157
let body: string | unknown;
155158
try {

packages/server/src/server/webStandardStreamableHttp.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,10 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
594594
return this.createJsonErrorResponse(415, -32000, 'Unsupported Media Type: Content-Type must be application/json');
595595
}
596596

597-
// Build request info from headers
597+
// Build request info from headers and URL
598598
const requestInfo: RequestInfo = {
599-
headers: Object.fromEntries(req.headers.entries())
599+
headers: Object.fromEntries(req.headers.entries()),
600+
url: req.url
600601
};
601602

602603
let rawMessage;

packages/server/test/server/sse.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const createMockResponse = () => {
2020
return res as unknown as Mocked<http.ServerResponse>;
2121
};
2222

23-
const createMockRequest = ({ headers = {}, body }: { headers?: Record<string, string>; body?: string } = {}) => {
23+
const createMockRequest = ({ headers = {}, body, url = '/messages' }: { headers?: Record<string, string>; body?: string; url?: string } = {}) => {
2424
const mockReq = {
2525
headers,
2626
body: body ? body : undefined,
27+
url,
2728
auth: {
2829
token: 'test-token'
2930
},
@@ -313,7 +314,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
313314
'user-agent': 'node',
314315
'accept-encoding': 'gzip, deflate',
315316
'content-length': '124'
316-
}
317+
},
318+
url: `/?sessionId=${sessionId}`
317319
})
318320
}
319321
]
@@ -418,7 +420,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
418420
requestInfo: {
419421
headers: {
420422
'content-type': 'application/json'
421-
}
423+
},
424+
url: '/messages'
422425
}
423426
}
424427
);

packages/server/test/server/streamableHttp.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
454454
'user-agent': expect.any(String),
455455
'accept-encoding': expect.any(String),
456456
'content-length': expect.any(String)
457-
}
457+
},
458+
url: baseUrl.toString()
458459
});
459460
});
460461

0 commit comments

Comments
 (0)