Refactor MCP fetch method and update CustomMCP documentation to include variable usage in headers
This commit is contained in:
parent
d49b43e85e
commit
a13dffa3b5
|
|
@ -27,6 +27,16 @@ For example, you have a variable called "var1":
|
|||
}
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
For example, when using SSE, you can use the variable "var1" in the headers:
|
||||
\`\`\`json
|
||||
{
|
||||
"url": "https://api.example.com/endpoint/sse",
|
||||
"headers": {
|
||||
"Authorization": "Bearer {{$vars.var1}}"
|
||||
}
|
||||
}
|
||||
\`\`\`
|
||||
`
|
||||
|
||||
class Custom_MCP implements INode {
|
||||
|
|
|
|||
|
|
@ -70,15 +70,8 @@ export class MCPToolkit extends BaseToolkit {
|
|||
headers: this.serverParams.headers
|
||||
},
|
||||
eventSourceInit: {
|
||||
// Reference: https://github.com/modelcontextprotocol/typescript-sdk/issues/118
|
||||
async fetch(input: Request | URL | string, init?: RequestInit) {
|
||||
const headers = new Headers(init?.headers || {})
|
||||
Object.entries(this.serverParams.headers).forEach(([key, value]) => {
|
||||
headers.set(key, value as string)
|
||||
})
|
||||
return fetch(input, { ...init, headers })
|
||||
}
|
||||
} as any
|
||||
fetch: (url, init) => fetch(url, { ...init, headers: this.serverParams.headers })
|
||||
}
|
||||
})
|
||||
} else {
|
||||
transport = new SSEClientTransport(baseUrl)
|
||||
|
|
|
|||
Loading…
Reference in New Issue