-
Notifications
You must be signed in to change notification settings - Fork 649
feat: Add mcprouter's MCP marketplace api support #727
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86cdd3c
wip: add mcp market
zerob13 f8c87a6
feat: mcp market install
zerob13 d135dcb
wip: mcp install status sync
zerob13 6961ca8
feat: mcp server config mask
zerob13 53683a4
chore: remove working doc
zerob13 5bd3a4c
chore: add translate
zerob13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import { IConfigPresenter, MCPServerConfig } from '@shared/presenter' | ||
|
|
||
| type McpRouterListResponse = { | ||
| code: number | ||
| message: string | ||
| data?: { | ||
| servers: Array<{ | ||
| uuid: string | ||
| created_at: string | ||
| updated_at: string | ||
| name: string | ||
| author_name: string | ||
| title: string | ||
| description: string | ||
| content?: string | ||
| server_key: string | ||
| config_name?: string | ||
| server_url?: string | ||
| }> | ||
| } | ||
| } | ||
|
|
||
| type McpRouterGetResponse = { | ||
| code: number | ||
| message: string | ||
| data?: { | ||
| created_at: string | ||
| updated_at: string | ||
| name: string | ||
| author_name: string | ||
| title: string | ||
| description: string | ||
| content?: string | ||
| server_key: string | ||
| config_name: string | ||
| server_url: string | ||
| } | ||
| } | ||
|
|
||
| const LIST_ENDPOINT = 'https://api.mcprouter.to/v1/list-servers' | ||
| const GET_ENDPOINT = 'https://api.mcprouter.to/v1/get-server' | ||
|
|
||
| export class McpRouterManager { | ||
| constructor(private readonly configPresenter: IConfigPresenter) {} | ||
|
|
||
| private getCommonHeaders(): Record<string, string> { | ||
| return { | ||
| 'Content-Type': 'application/json', | ||
| 'HTTP-Referer': 'deepchatai.cn', | ||
| 'X-Title': 'DeepChat' | ||
| } | ||
| } | ||
zerob13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async listServers(page: number, limit: number): Promise<McpRouterListResponse['data']> { | ||
| const res = await fetch(LIST_ENDPOINT, { | ||
| method: 'POST', | ||
| headers: this.getCommonHeaders(), | ||
| body: JSON.stringify({ page, limit }) | ||
| }) | ||
| if (!res.ok) throw new Error(`McpRouter list failed: HTTP ${res.status}`) | ||
| const json = (await res.json()) as McpRouterListResponse | ||
| if (json.code !== 0) throw new Error(json.message || 'List servers error') | ||
| return json.data || { servers: [] } | ||
| } | ||
zerob13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async getServer(serverKey: string): Promise<McpRouterGetResponse['data']> { | ||
| const apiKey = this.configPresenter.getSetting<string>('mcprouterApiKey') || '' | ||
| if (!apiKey) throw new Error('McpRouter API key missing') | ||
| const headers = { | ||
| ...this.getCommonHeaders(), | ||
| Authorization: `Bearer ${apiKey}` | ||
| } | ||
| const res = await fetch(GET_ENDPOINT, { | ||
| method: 'POST', | ||
| headers, | ||
| body: JSON.stringify({ server: serverKey }) | ||
| }) | ||
| if (!res.ok) throw new Error(`McpRouter get failed: HTTP ${res.status}`) | ||
| const json = (await res.json()) as McpRouterGetResponse | ||
| if (json.code !== 0 || !json.data) throw new Error(json.message || 'Get server error') | ||
| return json.data | ||
| } | ||
zerob13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private pickRandomEmoji(): string { | ||
| const emojis = ['🧩', '🛠️', '⚙️', '🚀', '🔧', '🧪', '📦', '🛰️', '🧠', '🔌', '📡', '🗂️'] | ||
| const idx = Math.floor(Math.random() * emojis.length) | ||
| return emojis[idx] | ||
| } | ||
|
|
||
| /** | ||
| * Install a server from McpRouter to local MCP config as HTTP (Streamable) server | ||
| */ | ||
| async installServer(serverKey: string): Promise<boolean> { | ||
| const detail = await this.getServer(serverKey) | ||
| if (!detail) throw new Error('Server detail not found') | ||
|
|
||
| const apiKey = this.configPresenter.getSetting<string>('mcprouterApiKey') || '' | ||
| if (!apiKey) throw new Error('McpRouter API key missing') | ||
|
|
||
| // Build MCPServerConfig | ||
| const config: MCPServerConfig = { | ||
| command: '', | ||
| args: [], | ||
| env: {}, | ||
| descriptions: detail.description || detail.title || detail.name, | ||
| icons: this.pickRandomEmoji(), | ||
| autoApprove: ['all'], | ||
| disable: false, | ||
| type: 'http', | ||
| baseUrl: detail.server_url, | ||
| customHeaders: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: `Bearer ${apiKey}`, | ||
| 'HTTP-Referer': 'deepchatai.cn', | ||
| 'X-Title': 'DeepChat' | ||
| }, | ||
| source: 'mcprouter', | ||
| sourceId: serverKey | ||
| } | ||
|
|
||
| const serverName = detail.config_name || detail.server_key || detail.name | ||
| return await this.configPresenter.addMcpServer(serverName, config) | ||
| } | ||
zerob13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.