🚀 feat: Add Initial MCP Support (Tools) to Agents and Assistants (#183)

This commit is contained in:
Danny Avila
2024-12-17 13:17:13 -05:00
committed by GitHub
parent 803ff0bf7f
commit 9156f9a024
8 changed files with 297 additions and 3 deletions

View File

@@ -0,0 +1,2 @@
- Added initial MCP Support (Tools) for Agents and Assistants
- Requires editing `librechat.yaml` with new `mcpServers` object config

View File

@@ -0,0 +1,13 @@
---
date: 2024/12/17
title: ⚙️ Config v1.2.0
---
import { ChangelogHeader } from '@/components/changelog/ChangelogHeader'
import Content from '@/components/changelog/content/config_v1.2.0.mdx'
<ChangelogHeader />
---
<Content />

View File

@@ -16,6 +16,7 @@ This file enables the integration of custom AI endpoints, enabling you to connec
- **Advanced Customization**: Configure file handling, rate limiting, user registration, and interface elements to align with your preferences and requirements.
- **Model Specifications**: Define detailed model configurations, presets, and behaviors to deliver a tailored AI experience.
- **Agents**: Use Provider-agnostic, no-code assistants, with options to customize capabilities.
- **MCP Servers**: Integrate with the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) for tool integrations.
- **Assistants Integration**: Leverage the power of OpenAI's Assistants API, with options to customize capabilities, polling intervals, and timeouts.
- **Azure OpenAI Support**: Integrate with Azure OpenAI Service, enabling access to multiple deployments, region models, and serverless inference endpoints.

View File

@@ -5,6 +5,7 @@ export default {
model_specs: 'Model Specs',
registration: 'Registration',
agents: 'Agents',
mcp_servers: 'MCP Servers',
aws_bedrock: 'AWS Bedrock',
assistants_endpoint: 'Assistants API',
custom_endpoint: 'Custom Endpoint',

View File

@@ -292,6 +292,67 @@ see: [Model Specs Object Structure](/docs/configuration/librechat_yaml/object_st
]}
/>
## mcpServers
**Key:**
<OptionTable
options={[
['mcpServers', 'Object', 'Defines the configuration for Model Context Protocol (MCP) servers, allowing dynamic integration of MCP servers within the application.', ''],
]}
/>
**Subkeys:**
<OptionTable
options={[
['<serverName>', 'Object', 'Each key under `mcpServers` represents an individual MCP server configuration, identified by a unique name.', ''],
]}
/>
- **Notes**:
- Initialization happens at startup, and the app must be restarted for changes to take effect.
- The `<serverName>` is a unique identifier for each MCP server configuration.
- Each MCP server can be configured using one of three connection types:
- `stdio`
- `websocket`
- `sse`
- The `type` field specifies the connection type to the MCP server.
- If `type` is omitted, it defaults based on the presence and format of `url` or `command`:
- If `url` is specified and starts with `http` or `https`, `type` defaults to `sse`.
- If `url` is specified and starts with `ws` or `wss`, `type` defaults to `websocket`.
- If `command` is specified, `type` defaults to `stdio`.
- see: [MCP Servers Object Structure](/docs/configuration/librechat_yaml/object_structure/mcp_servers)
**Example:**
```yaml filename="mcpServers"
mcpServers:
everything:
# type: sse # type can optionally be omitted
url: http://localhost:3001/sse
puppeteer:
type: stdio
command: npx
args:
- -y
- "@modelcontextprotocol/server-puppeteer"
filesystem:
# type: stdio
command: npx
args:
- -y
- "@modelcontextprotocol/server-filesystem"
- /home/user/LibreChat/
iconPath: /home/user/LibreChat/client/public/assets/logo.svg
mcp-obsidian:
command: npx
args:
- -y
- "mcp-obsidian"
- /path/to/obsidian/vault
```
see: [MCP Servers Object Structure](/docs/configuration/librechat_yaml/object_structure/mcp_servers)
## Additional links
- [AWS Bedrock Object Structure](/docs/configuration/librechat_yaml/object_structure/aws_bedrock)
- [Custom Endpoint Object Structure](/docs/configuration/librechat_yaml/object_structure/custom_endpoint)

View File

@@ -0,0 +1,175 @@
# MCP Servers Object Structure
## Example
```yaml filename="MCP Servers Object Structure"
# Example MCP Servers Object Structure
mcpServers:
everything:
# type: sse # type can optionally be omitted
url: http://localhost:3001/sse
puppeteer:
type: stdio
command: npx
args:
- -y
- "@modelcontextprotocol/server-puppeteer"
filesystem:
# type: stdio
command: npx
args:
- -y
- "@modelcontextprotocol/server-filesystem"
- /home/user/LibreChat/
iconPath: /home/user/LibreChat/client/public/assets/logo.svg
mcp-obsidian:
command: npx
args:
- -y
- "mcp-obsidian"
- /path/to/obsidian/vault
```
## `<serverName>`
**Key:**
<OptionTable
options={[
['<serverName>', 'Object', 'Each key under `mcpServers` represents an individual MCP server configuration, identified by a unique name. This name is used to reference the server configuration within the application.', ''],
]}
/>
### Subkeys
<OptionTable
options={[
['type', 'String', 'Specifies the connection type to the MCP server. Valid options are `"stdio"`, `"websocket"`, or `"sse"`. If omitted, it defaults based on the presence and format of `url` or `command`.', 'type: "stdio"'],
['command', 'String', '(For `stdio` type) The command or executable to run to start the MCP server.', 'command: "npx"'],
['args', 'Array of Strings', '(For `stdio` type) Command line arguments to pass to the `command`.', 'args: ["-y", "@modelcontextprotocol/server-puppeteer"]'],
['url', 'String', '(For `websocket` or `sse` type) The URL to connect to the MCP server.', 'url: "http://localhost:3001/sse"'],
['iconPath', 'String', '(Optional) Defines the tool\'s display icon shown in the tool selection dialog.', 'iconPath: "/path/to/icon.svg"'],
['env', 'Object', '(Optional, `stdio` type only) Environment variables to use when spawning the process.', 'env:\n NODE_ENV: "production"'],
['stderr', 'String or Stream or Number', '(Optional, `stdio` type only) How to handle `stderr` of the child process. Defaults to `"inherit"`.', 'stderr: "inherit"'],
]}
/>
#### `type`
- **Type:** String
- **Description:** Specifies the connection type to the MCP server. Valid options are `"stdio"`, `"websocket"`, or `"sse"`.
- **Default Value:** Determined based on the presence and format of `url` or `command`.
#### `command`
- **Type:** String
- **Description:** (For `stdio` type) The command or executable to run to start the MCP server.
#### `args`
- **Type:** Array of Strings
- **Description:** (For `stdio` type) Command line arguments to pass to the `command`.
#### `url`
- **Type:** String
- **Description:** (For `websocket` or `sse` type) The URL to connect to the MCP server.
- **Notes:**
- For `sse` type, the URL must start with `http://` or `https://`.
- For `websocket` type, the URL must start with `ws://` or `wss://`.
#### `iconPath`
- **Type:** String (Optional)
- **Description:** Defines the tool's display icon shown in the tool selection dialog.
#### `env`
- **Type:** Object (Optional, `stdio` type only)
- **Description:** Environment variables to use when spawning the process.
#### `stderr`
- **Type:** String or Stream or Number (Optional, `stdio` type only)
- **Description:** How to handle `stderr` of the child process. This matches the semantics of Node's [`child_process.spawn`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options).
- **Default Value:** `"inherit"` (messages to `stderr` will be printed to the parent process's `stderr`).
### Notes
- **Type Inference:**
- If `type` is omitted:
- If `url` is specified and starts with `http://` or `https://`, `type` defaults to `sse`.
- If `url` is specified and starts with `ws://` or `wss://`, `type` defaults to `websocket`.
- If `command` is specified, `type` defaults to `stdio`.
- **Connection Types:**
- **`stdio`**: Starts an MCP server as a child process and communicates via standard input/output.
- **`websocket`**: Connects to an external MCP server via WebSocket.
- **`sse`**: Connects to an external MCP server via Server-Sent Events (SSE).
## Examples
### `stdio` MCP Server
```yaml filename="stdio MCP Server"
puppeteer:
type: stdio
command: npx
args:
- -y
- "@modelcontextprotocol/server-puppeteer"
env:
NODE_ENV: "production"
stderr: inherit
```
### `sse` MCP Server
```yaml filename="sse MCP Server"
everything:
url: http://localhost:3001/sse
```
### `websocket` MCP Server
```yaml filename="websocket MCP Server"
myWebSocketServer:
url: ws://localhost:8080
```
### MCP Server with Custom Icon
```yaml filename="MCP Server with Icon"
filesystem:
command: npx
args:
- -y
- "@modelcontextprotocol/server-filesystem"
- /home/user/LibreChat/
iconPath: /home/user/LibreChat/client/public/assets/logo.svg
```
---
**Importing MCP Server Configurations**
The `mcpServers` configurations allow LibreChat to dynamically interact with various MCP servers, which can perform specialized tasks or provide specific functionalities within the application. This modular approach facilitates extending the application's capabilities by simply adding or modifying server configurations.
---
## Additional Information
- **Default Behavior:**
- Initialization happens at startup, and the app must be restarted for changes to take effect.
- If both `url` and `command` are specified, the `type` must be explicitly defined to avoid ambiguity.
- **Environment Variables (`env`):**
- Useful for setting up specific runtime environments or configurations required by the MCP server process.
- **Error Handling (`stderr`):**
- Configuring `stderr` allows you to manage how error messages from the MCP server process are handled. The default `"inherit"` means that the errors will be printed to the parent process's `stderr`.
## References
- [Model Context Protocol (MCP) Documentation](https://github.com/anthropic/mcp)
- [Node.js child_process.spawn](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options)
---
By properly configuring the `mcpServers` in your `librechat.yaml`, you can enhance LibreChat's functionality and integrate custom tools and services seamlessly.

View File

@@ -71,13 +71,12 @@ Agents can also be enhanced with various built-in tools:
- **Traversaal**: A robust search API for LLM Agents
- **Wolfram**: Computational and mathematical capabilities
- More tool integrations are planned, including [Model Context Provider](https://github.com/danny-avila/LibreChat/issues/4876) support.
- Tools can be disabled using the [`librechat.yaml`](/docs/configuration/librechat_yaml) configuration file:
- [More info](/docs/configuration/librechat_yaml/object_structure/agents#capabilities)
### Actions
With the Actions capability, you can dynamically create tools from OpenAPI specs to add to your Agents.
With the Actions capability, you can dynamically create tools from [OpenAPI specs](https://swagger.io/specification/) to add to your Agents.
![Agents - Endpoints Menu](/images/agents/actions.png)
@@ -90,6 +89,48 @@ With the Actions capability, you can dynamically create tools from OpenAPI specs
- Individual domains can be whitelisted for agent actions:
- [More info](/docs/configuration/librechat_yaml/object_structure/actions#alloweddomains)
### Model Context Protocol (MCP)
MCP is an open protocol that standardizes how applications provide context to Large Language Models (LLMs), acting like a universal adapter for AI tools and data sources.
Imagine MCP as the "USB-C of AI" - just as USB-C provides a universal connection standard for electronic devices, MCP offers a standardized way to connect AI models to diverse tools, data sources, and services.
By configuring `mcpServers` in the `librechat.yaml` file, you can:
- Add custom tools from various sources
- Integrate specialized data access tools
- Extend AI capabilities beyond default offerings
Here are some tools added by configuring the ["Filesystem" MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem):
![Agents - MCP](/images/agents/mcp_tools.png)
Key Features:
- Upon app restart, tools are available in the "Add Tools" button within the Agent Builder panel
- Seamlessly connect custom tools and data sources
- Leverage a growing ecosystem of MCP-compatible servers and integrations
Learn More:
- [Configuring MCP Servers](/docs/configuration/librechat_yaml/object_structure/mcp_servers)
- [Model Context Protocol Introduction](https://modelcontextprotocol.io/introduction)
#### ⚠️ MCP Limitations
Most existing MCP servers use `stdio` processes, which work well for local, single-user environments but pose significant challenges for multi-user and production platforms.
**The Challenges**
- STDIO servers are designed for local, single-user contexts
- Not scalable for remote or cloud deployments
- Limited multi-user support (concurrency, authentication, security)
**Emerging Solutions**
Server-Sent Events (SSE) are being explored as a more scalable transport mechanism. MCP developers are actively working on remote connection support, addressing complexities around deployment, authentication, and security.
**Current Status:** Promising, but still a work in progress.
LibreChat is at the forefront of implementing flexible, scalable MCP server integrations to support diverse usage scenarios.
## File Management
Agents support three distinct file upload categories:
@@ -160,7 +201,7 @@ Future updates will include:
- General improvements to the current Agent experience
- Multi-agent orchestration for complex workflows
- Ability to customize agents for various functions: titling (chat thread naming), memory management (user context/history), and prompt enhancement (input assistance/predictions)
- More tools, tool parameters, and [Model Context Provider](https://github.com/danny-avila/LibreChat/issues/4876) support for tools and file resources.
- More tools, configurable tool parameters, dynamic tool creation.
Furthermore, the update introduces a new paradigm for LibreChat, as its underlying architecture provides a much needed refresh for the app, optimizing both the user experience and overall app performance.

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB