llm-mcp
A Ruby gem for integrating Large Language Models (LLMs) via the Model Context Protocol (MCP) into development workflows.
llm-mcp
A Ruby gem that exposes Large Language Models (LLMs) via the Model Context Protocol (MCP), enabling seamless integration of AI capabilities into your development workflow.
Overview
llm-mcp creates an MCP server that provides standardized access to various LLM providers (OpenAI, Google Gemini, and OpenAI-compatible APIs) while supporting advanced features like session management, conversation persistence, and integration with external MCP tools.
Key Features
- 🤖 Multi-Provider Support: Works with OpenAI, Google Gemini, and any OpenAI-compatible API
- 💬 Session Management: Persist conversations across server restarts
- 🔧 MCP Tool Integration: Connect to external MCP servers and use their tools within LLM conversations
- 📝 Comprehensive Logging: JSON-formatted logs for debugging and analysis
- 🔌 Extensible Architecture: Easy to add new providers and customize behavior
- 🚀 Built on FastMCP: Leverages the fast and efficient MCP server framework
Installation
Add this line to your application's Gemfile:
gem 'llm-mcp'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install llm-mcp
Configuration
Environment Variables
Set up your API keys based on the provider you want to use:
# For OpenAI
export OPENAI_API_KEY="your-openai-api-key"
# For Google Gemini
export GEMINI_API_KEY="your-gemini-api-key"
# or
export GOOGLE_API_KEY="your-google-api-key"
Usage
Basic Usage
Start an MCP server that exposes an LLM:
# Using OpenAI
llm-mcp mcp-serve --provider openai --model gpt-4
# Using Google Gemini
llm-mcp mcp-serve --provider google --model gemini-1.5-flash
# Using a custom OpenAI-compatible API
llm-mcp mcp-serve --provider openai --model llama-3.1-8b --base-url https://api.groq.com/openai/v1
Advanced Options
llm-mcp mcp-serve \
--provider openai \
--model gpt-4 \
--verbose \ # Enable verbose logging
--json-log-path logs/llm.json \ # Log to JSON file
--session-id my-project \ # Resume a specific session
--session-path ~/my-sessions \ # Custom session storage location
--append-system-prompt "You are a Ruby expert" \ # Add to system prompt
--skip-model-validation # Skip model name validation
Connecting to External MCP Servers
llm-mcp can connect to other MCP servers, allowing the LLM to use their tools:
- Create an MCP configuration file (e.g.,
~/.mcp/config.json):
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["@modelcontextprotocol/server-filesystem", "/tmp"]
},
"github": {
"command": "mcp-github",
"env": {
"GITHUB_TOKEN": "your-github-token"
}
},
"http-api": {
"url": "https://api.example.com/mcp/sse",
"transport": "sse",
"headers": {
"Authorization": "Bearer your-token"
}
}
}
}
- Start llm-mcp with the configuration:
llm-mcp mcp-serve \
--provider openai \
--model gpt-4 \
--mcp-config ~/.mcp/config.json
Now the LLM can use tools from the connected MCP servers in its responses!
MCP Tools Exposed
task
Send a request to the LLM and get a response.
Parameters:
prompt(required): The message or question for the LLMtemperature(optional): Control randomness (0.0-2.0, default: 0.7)max_tokens(optional): Maximum response length
Example Request:
{
"method": "tools/call",
"params": {
"name": "task",
"arguments": {
"prompt": "Explain the concept of dependency injection",
"temperature": 0.7,
"max_tokens": 500
}
}
}
reset_session
Clear the conversation history and start fresh.
Example Request:
{
"method": "tools/call",
"params": {
"name": "reset_session",
"arguments": {}
}
}
Session Management
Sessions automatically persist conversations to disk, allowing you to:
- Resume previous conversations
- Maintain context across server restarts
- Track token usage over time
Sessions are stored in ~/.llm-mcp/sessions/ by default, with each session saved as a JSON file.
Session Files
Session files contain:
- Message history (user, assistant, and system messages)
- Timestamps for each interaction
- Token usage statistics
- Session metadata
Logging
Enable JSON logging for comprehensive debugging:
llm-mcp mcp-serve \
--provider openai \
--model gpt-4 \
--json-log-path logs/llm.json \
--verbose
Logs include:
- All requests and responses
- Tool calls and their results
- Session operations
- Error messages and stack traces
Integration Examples
Using with Claude Desktop
Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"llm-mcp": {
"command": "llm-mcp",
"args": ["mcp-serve", "--provider", "openai", "--model", "gpt-4"],
"env": {
"OPENAI_API_KEY": "your-api-key"
}
}
}
}
Using with mcp-client
require 'mcp-client'
client = MCP::Client.new
client.connect_stdio('llm-mcp', 'mcp-serve', '--provider', 'openai', '--model', 'gpt-4')
# Use the task tool
response = client.call_tool('task', {
prompt: "Write a haiku about Ruby programming",
temperature: 0.9
})
puts response.content
Combining Multiple MCP Servers
Create a powerful AI assistant by combining llm-mcp with other MCP servers:
{
"mcpServers": {
"llm": {
"command": "llm-mcp",
"args": ["mcp-serve", "--provider", "openai", "--model", "gpt-4", "--mcp-config", "mcp-tools.json"]
},
"filesystem": {
"command": "mcp-filesystem",
"args": ["/project"]
},
"git": {
"command": "mcp-git"
}
}
}
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests.
# Install dependencies
bundle install
# Run tests
bundle exec rake test
# Run linter
bundle exec rubocop -A
# Install gem locally
bundle exec rake install
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/parruda/llm-mcp.
License
The gem is available as open source under the terms of the MIT License.
Verwandte Server
Scout Monitoring MCP
SponsorPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
SponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
XcodeBuildMCP
Popular MCP server that enables AI agents to scaffold, build, run and test iOS, macOS, visionOS and watchOS apps or simulators and wired and wireless devices. It has powerful UI-automation capabilities like controlling the simulator, capturing run-time logs, as well as taking screenshots and viewing the accessibility hierarchy.
idb-mcp
An MCP server that uses Facebook IDB to automate iOS simulators, providing device control, input actions, and screenshots over HTTP, SSE, or stdio.
AIR Blackbox
EU AI Act compliance scanner for Python AI agents — 10 tools for scanning, analysis, and remediation
VibeShift
An intelligent security agent that analyzes AI-generated code for vulnerabilities and assists with remediation.
AiCore Project
A unified framework for integrating various language models and embedding providers to generate text completions and embeddings.
Recent Go MCP Server
Provides Go language updates and best practices in a structured Markdown format for LLM coding agents.
FeedOracle Macro Intelligence
Deterministic macro regime engine for AI trading agents — RISK_ON / NEUTRAL / RISK_OFF / STRESS with transparent scoring rules.
Lightning Tools MCP Server
An MCP server for accessing useful Bitcoin Lightning tools.
openEuler MCP Servers
A collection of MCP servers designed to enhance the interaction experience with the openEuler operating system.
VideoDB
Server for advanced AI-driven video editing, semantic search, multilingual transcription, generative media, voice cloning, and content moderation.