Skip to content

Commit 117c1cc

Browse files
committed
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.
1 parent f82c997 commit 117c1cc

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@modelcontextprotocol/core": minor
3+
"@modelcontextprotocol/server": minor
4+
---
5+
6+
Add `url` property to `RequestInfo` interface, exposing the request URL to server handlers

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: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ 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 = ({
24+
headers = {},
25+
body,
26+
url = '/messages'
27+
}: { headers?: Record<string, string>; body?: string; url?: string } = {}) => {
2428
const mockReq = {
2529
headers,
2630
body: body ? body : undefined,
31+
url,
2732
auth: {
2833
token: 'test-token'
2934
},
@@ -313,7 +318,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
313318
'user-agent': 'node',
314319
'accept-encoding': 'gzip, deflate',
315320
'content-length': '124'
316-
}
321+
},
322+
url: `/?sessionId=${sessionId}`
317323
})
318324
}
319325
]
@@ -418,7 +424,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
418424
requestInfo: {
419425
headers: {
420426
'content-type': 'application/json'
421-
}
427+
},
428+
url: '/messages'
422429
}
423430
}
424431
);

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)