-
Notifications
You must be signed in to change notification settings - Fork 0
feat: update @modelcontextprotocol/sdk to version 1.13.2 and refactor… #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,14 +1,16 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { experimental_createMCPClient as createMCPClientSDK } from 'ai'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const createMCPClient = () => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createMCPClientSDK({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| transport: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'sse', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // biome-ignore lint/style/noNonNullAssertion: <explanation> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: process.env.MCP_ROUTER_SERVER_URL!, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // biome-ignore lint/style/noNonNullAssertion: <explanation> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'x-api-key': process.env.MCP_ROUTER_SERVER_API_KEY!, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const createMCPClient = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // biome-ignore lint/style/noNonNullAssertion: <explanation> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const url = new URL(process.env.MCP_ROUTER_SERVER_URL!); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // add x-api-key to the url | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // biome-ignore lint/style/noNonNullAssertion: <explanation> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url.searchParams.set('x-api-key', process.env.MCP_ROUTER_SERVER_API_KEY!); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const transport = new StreamableHTTPClientTransport(url, {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return createMCPClientSDK({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| transport, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and environment variable validation. The function uses non-null assertions without validating required environment variables, which could lead to runtime errors. export const createMCPClient = () => {
+ const serverUrl = process.env.MCP_ROUTER_SERVER_URL;
+ const apiKey = process.env.MCP_ROUTER_SERVER_API_KEY;
+
+ if (!serverUrl) {
+ throw new Error('MCP_ROUTER_SERVER_URL environment variable is required');
+ }
+
+ if (!apiKey) {
+ throw new Error('MCP_ROUTER_SERVER_API_KEY environment variable is required');
+ }
+
+ let url: URL;
+ try {
+ url = new URL(serverUrl);
+ } catch (error) {
+ throw new Error(`Invalid MCP_ROUTER_SERVER_URL: ${error.message}`);
+ }
+
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
- const url = new URL(process.env.MCP_ROUTER_SERVER_URL!);
- // add x-api-key to the url
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
- url.searchParams.set('x-api-key', process.env.MCP_ROUTER_SERVER_API_KEY!);
- const transport = new StreamableHTTPClientTransport(url, {});
+ const transport = new StreamableHTTPClientTransport(url, {
+ headers: {
+ 'x-api-key': apiKey
+ }
+ });📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security concern: API key exposed in URL query parameters.
Adding the API key as a URL query parameter poses security risks as query parameters can be logged in server logs, browser history, and proxy logs. Consider using headers or request body instead.
Then pass the API key via headers in the transport options:
🤖 Prompt for AI Agents