A simple wrapper library for FastMCP + Starlette
Project description
viyv_mcp
viyv_mcp is a lightweight Python wrapper around FastMCP and Starlette that simplifies creating MCP (Model Context Protocol) servers with minimal boilerplate.
๐ Quick Start
# Install the package
pip install viyv_mcp
# Create a new MCP server project
create-viyv-mcp new my_mcp_server
# Navigate to the project and install dependencies
cd my_mcp_server
uv sync
# Run the server
uv run python main.py
Your MCP server is now running at http://localhost:8000 ๐
Overview
viyv_mcp provides:
- CLI Tool: Generate production-ready MCP server projects instantly
- Decorator APIs: Register tools, resources, prompts, and agents with simple decorators
- Auto-registration: Automatically discover and register modules in your project
- External MCP Bridge: Connect and manage external MCP servers seamlessly
- Built-in Adapters: Ready-to-use integrations for Slack and OpenAI Agents
- Hot Reloading: Dynamic tool injection keeps your agents up-to-date
โจ Key Features
๐ ๏ธ Simple Tool Creation
from viyv_mcp import tool
@tool(description="Add two numbers")
def add(a: int, b: int) -> int:
return a + b
๐ค Agent Support
from viyv_mcp import agent
@agent(name="calculator", use_tools=["add", "subtract"])
async def calculator_agent(query: str) -> str:
# Your agent logic here
pass
๐ External MCP Server Bridge
// app/mcp_server_configs/playwright.json
{
"name": "playwright",
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
๐ Multiple Integration Options
- Slack: Built-in adapter for Slack bots and event handling
- OpenAI Agents: Bridge MCP tools to OpenAI function calling
- Custom Endpoints: Mount additional FastAPI apps with
@entry
๐ฆ Installation
pip install viyv_mcp
๐ Project Structure
When you create a new project with create-viyv-mcp new my_project, you get:
my_project/
โโโ main.py # Server entry point
โโโ pyproject.toml # Project dependencies (managed by uv)
โโโ Dockerfile # Container deployment ready
โโโ app/
โโโ config.py # Environment configuration
โโโ tools/ # Your MCP tools (@tool decorator)
โโโ resources/ # MCP resources (@resource decorator)
โโโ prompts/ # MCP prompts (@prompt decorator)
โโโ agents/ # AI agents (@agent decorator)
โโโ entries/ # Custom HTTP endpoints (@entry decorator)
โโโ mcp_server_configs/ # External MCP server configurations
๐ป Usage Examples
Creating Custom Tools
Create a file app/tools/my_tools.py:
from viyv_mcp import tool
from typing import Annotated
from pydantic import Field
def register(mcp):
@tool(description="Calculate the area of a rectangle")
def calculate_area(
width: Annotated[float, Field(description="Width of the rectangle")],
height: Annotated[float, Field(description="Height of the rectangle")]
) -> float:
"""Returns the area of a rectangle"""
return width * height
Creating Resources
Create a file app/resources/my_resources.py:
from viyv_mcp import resource
def register(mcp):
@resource("config://{key}")
def get_config(key: str) -> str:
"""Retrieve configuration values"""
configs = {
"api_version": "1.0",
"max_retries": "3"
}
return configs.get(key, "Not found")
Creating an Agent
Create a file app/agents/my_agent.py:
from viyv_mcp import agent
from viyv_mcp.openai_bridge import build_function_tools
@agent(name="math_agent", use_tools=["calculate_area", "add"])
async def math_agent(task: str) -> str:
"""An agent that can perform mathematical calculations"""
# Get available tools
tools = build_function_tools(use_tools=["calculate_area", "add"])
# Your agent logic here
return f"Completed task: {task}"
Bridging External MCP Servers
Add a JSON config file in app/mcp_server_configs/:
{
"name": "filesystem",
"command": "npx",
"args": ["@modelcontextprotocol/server-filesystem", "/path/to/workspace"],
"env": {}
}
The external server's tools will be automatically available in your MCP server!
Slack Integration
Create a file app/entries/slack_entry.py:
from viyv_mcp import entry
from viyv_mcp.app.adapters.slack_adapter import SlackAdapter
from viyv_mcp.run_context import RunContext
@entry("/slack")
def create_slack_app():
adapter = SlackAdapter(
bot_token="xoxb-your-bot-token",
signing_secret="your-signing-secret",
context_cls=RunContext,
)
return adapter.as_fastapi_app()
Custom API Endpoints
Create a file app/entries/api.py:
from viyv_mcp import entry
from fastapi import FastAPI
@entry("/api/v1")
def create_api():
app = FastAPI()
@app.get("/status")
def get_status():
return {"status": "operational", "version": "1.0"}
return app
๐ง Configuration
Environment variables you can set:
HOST: Server host (default:127.0.0.1)PORT: Server port (default:8000)BRIDGE_CONFIG_DIR: Directory for external MCP configs (default:app/mcp_server_configs)STATIC_DIR: Static files directory (default:static/images)
๐๏ธ Advanced Features
Auto-registration
All modules in app/tools/, app/resources/, app/prompts/, and app/agents/ are automatically registered if they have a register(mcp) function.
Dynamic Tool Injection
Tools are dynamically injected into agents on each request, ensuring they always have access to the latest available tools.
Session Context
Tools can access session context (e.g., Slack events) through the RunContextWrapper parameter.
๐ Examples
Check out the example/ directory for complete working examples:
- claude_code_mcp: MCP server that exposes Claude Code CLI functionality
- test: Comprehensive example with Slack integration and various agents
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
# Clone the repository
git clone https://github.com/BrainFiber/viyv_mcp
cd viyv_mcp
# Install in development mode
pip install -e .
# Run tests
pytest
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ฅ Authors
- Hiroki Takezawa - BrainFiber
๐ Acknowledgments
- Built on top of FastMCP by jlowin
- Uses Starlette for ASGI framework
- Inspired by the Model Context Protocol specification
๐ฎ Support
- ๐ง Email: hiroki.takezawa@brainfiber.net
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file viyv_mcp-0.1.7.tar.gz.
File metadata
- Download URL: viyv_mcp-0.1.7.tar.gz
- Upload date:
- Size: 40.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0c95105fa2ece35695018c48b5faf3a1913bceb004788626ebc86c797edbce0
|
|
| MD5 |
acd306c3ae5588838eea47b74736f6a3
|
|
| BLAKE2b-256 |
17e01db647ab7ad0a57ac794b41de96140ca48e458fdcd67450221d0cd59ea97
|
File details
Details for the file viyv_mcp-0.1.7-py3-none-any.whl.
File metadata
- Download URL: viyv_mcp-0.1.7-py3-none-any.whl
- Upload date:
- Size: 48.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40106238f4fe9c54f05784cc25261127922468df0a925bf1fc2825aee6a1e368
|
|
| MD5 |
66ed3e19da3a6de055ff226b4af751b4
|
|
| BLAKE2b-256 |
269394e66ef15f370279f8d5fb7951467c132f2bdc998800a34a5942e1e15555
|