Commit a136797
authored
MCP (#1981)
* Update ServerCard.svelte
feat(mcp): add Model Context Protocol integration with tool support
Improve MCP tools caching and server selection logic
Replaces single-entry MCP tools cache with a multi-keyed cache based on server configuration, improving cache accuracy for different server sets. Refactors server selection logic in runMcpFlow to better handle custom server lists and selected server names. Removes MCP flow from generate.ts, streamlining text generation logic.
* Add OAuth authentication for MCP servers
Introduces browser-based OAuth flow for MCP servers, including new auth helpers, localStorage management, and UI actions for authentication and sign-out. Server cards now support authentication, and enabled servers include persisted auth headers for API requests. Adds callback handler and route for OAuth completion.
* Add server authentication status and UI indicators
Introduces an 'authRequired' property to MCPServer and health check responses to indicate when authentication is needed. Updates ServerCard UI to show authentication badges and conditionally display Authenticate/Sign out buttons. Store now tracks authenticated server IDs and updates them on auth changes. Health check logic and error handling improved to detect and signal authentication requirements.
* Show MCP Servers button only for authenticated users
The MCP Servers button in NavMenu is now conditionally rendered for users with a username or email, ensuring only authenticated users can access server management. Also, MCPServerManager modal width and help text background color have been updated for improved UI consistency.
* format
* Refactor MCP client management and tool invocation
Introduces a pooled MCP client system for efficient reuse and connection management. Refactors tool invocation to support per-call timeouts, abort signals, and parallel execution with improved error handling. Ensures MCP clients are properly closed after each flow and updates related modules to use the new client pool and signal-aware APIs.
* Improve OAuth state generation and error handling
Replaces Math.random-based OAuth state with a cryptographically-strong random generator using Web Crypto API. Sanitizes error messages in the callback handler to prevent unsafe HTML embedding. Ensures token_type is trimmed and defaults to 'Bearer' in authentication headers.
* Update blue color shades and improve MCP server UI
Standardizes blue color usage across components for consistency, switching from blue-500 to blue-600 in buttons, borders, and backgrounds. Refactors MCPServerManager and ServerCard to use a Switch component for enabling servers, improving accessibility and code clarity. Increases loop count in runMcpFlow.ts for more robust streaming. Updates multimodal model indicators to use blue-600 in dark mode for better visual alignment.
* Adjust input padding and card border styling
Reduced horizontal padding on AddServerForm input fields for improved layout. Updated ServerCard selected state to use semi-transparent blue border for better visual distinction.
* Improve provider metadata handling in text generation
Sanitizes tool/function names to comply with provider guidelines by replacing disallowed characters and limiting length. Enhances router metadata emission to support cases where only provider information is available, and captures the x-inference-provider header from upstream OpenAI-compatible servers to notify the UI of the provider used.
* Update ServerCard.svelte
* Add per-model tool calling support and overrides
Introduces a `supportsTools` flag for models to indicate tool/function calling capability, aggregates provider support, and adds per-model user overrides via settings. Updates UI to display tool support, enables forced tool calling, and ensures backend respects these settings during text generation and conversation flows.
* lint
* Enhance MCP client to append structuredContent
Updates the MCP HTTP client to append structuredContent as JSON to the textual output if provided by the server. Also bumps @modelcontextprotocol/sdk dependency to version 1.21.1.
* Refactor settings bindings for Svelte 5 compatibility
Replaces direct store mutations with functional bindings for settings fields in model and application settings pages, ensuring proper updates via store methods. Also updates ToolUpdate.svelte to use $derived.by for availableTools and initializes state variables with explicit undefined values.
* Update MCPServerManager.svelte
* Improve MCP server management UI and validation
Added a security warning to the AddServerForm and improved form styling. Updated MCPServerManager to clarify views, use a larger add icon, and show quick tips. ServerCard header styling was refined. MCP server store now prunes invalid selected server IDs after refresh.
* Add router tool support configuration
Introduces LLM_ROUTER_ENABLE_TOOLS environment variable and configures its usage in both .env and prod.yaml. Updates model processing to enable tool support for the router when the variable is set to true.
* Improve MCP server manager and card UI
* Refactor MCP icon and update app name usage
Extracted the MCP icon into a reusable IconMCP.svelte component and replaced inline SVG usage in MCPServerManager.svelte. Updated references to 'HuggingChat' to use the dynamic PUBLIC_APP_NAME from public config for better branding flexibility.
* Update model badges to use colored backgrounds
Replaces border-based styling for tool and multimodal badges with colored backgrounds and text for improved visual clarity in models and settings pages.
* Remove 'Base' label from ServerCard
Eliminates the conditional rendering of the 'Base' label for servers of type 'base' in the ServerCard component.
* Add router bypass for tool-capable models
Implements logic to bypass Arch routing and select a configured tool-capable model when tools are enabled and active, using new helpers in toolsRoute.ts. Updates environment and documentation to describe new LLM_ROUTER_TOOLS_MODEL config. Ensures fallback to Arch routing if no suitable model is found.
* Add <think> block handling for reasoning tokens
Introduces logic to merge provider-specific reasoning fields into <think> blocks within the token stream, mirroring OpenAI adapter behavior. Ensures <think> blocks are closed before final output and strips them from tool call messages to prevent confusion in follow-up reasoning.
* Update ChatInput.svelte
* Update ChatInput.svelte
* Update ChatInput.svelte
* Refactor formatting and fix indentation in server code
Improves code readability in toolsRoute.ts and runMcpFlow.ts by reformatting multi-line statements and correcting indentation. No functional changes were made.
* Handle user aborts quietly in runMcpFlow
* Remove namespaced tool aliases from OpenAI tools
* Update Switch.svelte
* Add navigation for tool update groups in chat
* Add MCP server favicon support and update config
* Fix router details rendering with missing metadata
Updates conditional rendering to check for the presence of 'route' in streamingRouterMetadata, preventing errors when metadata is undefined or missing the 'route' property.
* format
* Add model tool support indicator to chat UI
Introduces a `modelSupportsTools` prop to ChatInput and ChatWindow components to reflect whether the selected model supports tool calling. The MCP server indicator now visually changes and updates its tooltip based on tool support, improving user feedback for models without tool capabilities.
* Improve MCP health check URL validation and timeout
* Update server manager and card UI styles and labels
* Update prod.yaml
* Remove obsolete LLM log files
Deleted three outdated LLM log files related to chat completions for improved log management and reduced clutter.
* derive tool name in tool group
* Make MCP server count clickable to open manager
Replaces the MCP server count text in ChatInput with a button that opens the MCPServerManager. Also improves layout responsiveness in MCPServerManager for small screens.
* Update MCPServerManager.svelte
* Improve MCP server health check and tool response handling
* remove mcp oauth ...for now
* feat(chat): allow manual navigation of tool-call groups while streaming\n\n- Add toolAutoFollowLatest state to stop auto-snapping when user pages\n- Default to newest group while streaming; clamp index as groups change\n- Resume auto-follow when streaming ends or user returns to newest group\n\nAffects: src/lib/components/chat/ChatMessage.svelte
* feat(chat): show active tool call in footer and hide routing while calling\n\n- Derive current in-flight tool from assistant updates\n- Map to human-friendly displayName using page.data.tools\n- When a tool is actively running: render "Calling tool <name>" and skip the router/model status\n\nAffects: src/lib/components/chat/ChatWindow.svelte
* feat(mcp): optionally forward HF user token to official HF MCP endpoint\n\n- Add MCP_FORWARD_HF_USER_TOKEN config flag\n- Forward logged-in user's HF token to https://huggingface.co/mcp?login when no Authorization header is set\n- Apply overlay in runMcpFlow and in /api/mcp/health endpoint\n- Add shared helpers (hasAuthHeader, isStrictHfMcpLogin, hasNonEmptyToken)\n- Clarify client store comment about server-side overlay\n\nAffects: src/lib/server/config.ts, src/lib/server/textGeneration/mcp/runMcpFlow.ts, src/routes/api/mcp/health/+server.ts, src/lib/server/mcp/hf.ts, src/lib/stores/mcpServers.ts
* infra(chart): add read-mcp scope to OPENID_SCOPES for MCP access\n\n- Update dev and prod charts to request 'read-mcp' alongside 'openid profile inference-api'
* feat(prompt): include current date and image markdown hint in tool preprompt\n\n- Add today's date to tool preprompt for time-aware tools\n- Document how to inline generated images via markdown\n\nAffects: src/lib/server/textGeneration/utils/toolPrompt.ts
* chore(ui): minor formatting and cleanup in MCP ServerCard and conversation page import\n\n- Collapse named imports and remove stray blank lines in ServerCard\n- Normalize import whitespace in +page.svelte\n\nNo functional changes
* Update .env
* infra(chart): enable HF MCP token forwarding in dev and prod\n\n- Set MCP_FORWARD_HF_USER_TOKEN: 'true' in both dev and prod envs
* feat(mcp-ui): add Hugging Face MCP Settings button next to Health Check\n\n- Detects servers hosted on huggingface.co\n- Opens https://huggingface.co/settings/mcp in a new tab\n- Matches existing button styling and Svelte 5 runes patterns
* style(chat): remove image margins and add rounded-lg in conversation prose\n\n- Apply prose-img:my-0 and prose-img:rounded-lg to message and reasoning prose containers\n- Keeps change scoped to chat UI only
* Update toolPrompt.ts
* note sure about this
* Update MCP_SERVERS and tool config in dev and prod envs
* security: enforce URL safety in MCP generation path and factorize check\n\n- Add shared isValidUrl (HTTPS only, basic localhost/private checks; exact behavior from /api/mcp/health)\n- Apply guard in runMcpFlow before any MCP connections\n- Reuse the same validator in /api/mcp/health and /api/fetch-url\n- Keep function semantics identical to existing health route implementation
* ui: show HF MCP Settings button only for exact base URL (https://huggingface.co/mcp?login)\n\n- Add client util isStrictHfMcpLogin\n- Update ServerCard to check exact login URL instead of hostname match
* Handle tool name collisions with server suffixes
* Add documentation for MCP Tools integration
* format1 parent 0f4475d commit a136797
File tree
65 files changed
+5067
-281
lines changed- .github/workflows
- chart/env
- src
- lib
- components
- chat
- icons
- mcp
- server
- api/routes/groups
- endpoints
- openai
- mcp
- router
- textGeneration
- mcp
- utils
- stores
- types
- utils
- routes
- api
- fetch-url
- mcp
- health
- servers
- models
- conversation/[id]
- models
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
65 files changed
+5067
-281
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
| |||
113 | 118 | | |
114 | 119 | | |
115 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
116 | 126 | | |
117 | 127 | | |
118 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
145 | 182 | | |
146 | 183 | | |
147 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
| |||
0 commit comments