Kiwi MCP
A unified MCP server that consolidates directives, Python scripts, and knowledge management into four streamlined tools for AI agents. It enables users to search, load, and execute workflows or scripts within isolated virtual environments while maintaining a consistent interface for local and registry-based resources.
README
Kiwi MCP - Unified AI Agent Tools
A unified MCP (Model Context Protocol) server consolidating directives, scripts, and knowledge management into 4 simple tools.
Version: 0.1.0
Coverage: 30% (tests in progress)
Overview
Kiwi MCP reduces 17 tools from three separate MCPs into 4 unified tools with consistent interfaces:
| Tool | Purpose |
|---|---|
| search | Find directives, scripts, or knowledge entries (local or registry) |
| load | Download items from registry to local storage |
| execute | Run operations: publish, delete, create, update, link, run |
| help | Get usage guidance and troubleshooting |
Supported Types:
directive- Workflow guides and configurationsscript- Python execution scriptsknowledge- Zettelkasten knowledge entries
Installation
Prerequisites
- Python ≥3.11
- pip or poetry
From Source
cd kiwi-mcp
pip install -e ".[dev]"
Dependencies
mcp>=1.0.0- Model Context Protocolpydantic>=2.0.0- Data validationhttpx>=0.27.0- HTTP clientsupabase>=2.0.0- Registry backendpython-dotenv>=1.0.0- Environment configurationpyyaml>=6.0.0- YAML parsingaiofiles>=23.0.0- Async file I/O
Quick Start
Initialize
export SUPABASE_URL="https://your-project.supabase.co"
export SUPABASE_SECRET_KEY="your-secret-key"
# Run server
python -m kiwi_mcp.server
Usage Examples
Search for Directives
{
"tool": "search",
"arguments": {
"item_type": "directive",
"query": "authentication setup",
"source": "registry",
"limit": 10
}
}
Response:
{
"results": [
{
"name": "oauth_setup",
"category": "authentication",
"description": "Setup OAuth with Google and GitHub",
"quality_score": 95.0
}
]
}
Load a Script
{
"tool": "load",
"arguments": {
"item_type": "script",
"item_id": "google_maps_scraper",
"destination": "project",
"project_path": "/home/user/myproject"
}
}
Response:
{
"status": "loaded",
"name": "google_maps_scraper",
"version": "2.1.0",
"destination": "project",
"path": "/home/user/myproject/.ai/scripts/scraping/google_maps_scraper.py"
}
Run a Directive
{
"tool": "execute",
"arguments": {
"item_type": "directive",
"action": "run",
"item_id": "bootstrap_project",
"parameters": {
"project_name": "my_app",
"language": "python"
}
}
}
Response:
{
"action": "run",
"name": "bootstrap_project",
"source": "local",
"content": "# Bootstrap Directive\n1. Create project structure...",
"instructions": "Follow the directive steps above."
}
Publish to Registry
{
"tool": "execute",
"arguments": {
"item_type": "knowledge",
"action": "publish",
"item_id": "001-email-deliverability",
"parameters": {
"version": "1.0.0",
"changelog": "Initial release with best practices"
}
}
}
Tools Reference
search
Find items by natural language query across local and registry sources.
Parameters:
item_type(required):"directive","script", or"knowledge"query(required): Natural language search querysource(optional):"local","registry", or"all"(default:"local")limit(optional): Max results (default: 10)
Returns: JSON with results array or error
Examples:
# Search for email-related knowledge
search(
item_type="knowledge",
query="email deliverability",
source="registry"
)
# Search local scripts
search(
item_type="script",
query="scrape Google Maps",
limit=5
)
load
Download items from registry to local storage.
Parameters:
item_type(required):"directive","script", or"knowledge"item_id(required): Item identifierdestination(optional):"project"or"user"(default:"project")project_path(optional): Required ifdestination="project"version(optional): Specific version to load
Returns: JSON with status, path, and metadata
Examples:
# Load directive to project
load(
item_type="directive",
item_id="oauth_setup",
destination="project",
project_path="/home/user/myapp"
)
# Load knowledge to user space
load(
item_type="knowledge",
item_id="001-jwt-auth",
destination="user"
)
execute
Run operations on items: run, publish, delete, create, update, link.
Parameters:
item_type(required):"directive","script", or"knowledge"action(required):"run","publish","delete","create","update","link"item_id(required): Item identifierparameters(optional): Action-specific parameters dict- Additional parameters:
dry_run,project_path, etc.
Returns: JSON with operation result or error
Supported Actions (All Types):
All item types support the same 6 actions for consistency:
run- Execute/load the item (directives return parsed content, scripts execute with params, knowledge returns entry)publish- Publish to registry with versiondelete- Remove from local or registry (requiresconfirm: true)create- Create new item locallyupdate- Modify existing itemlink- Link to another item of the same type (e.g., directive → directive, script → script)
Type-Specific Behavior:
| Action | Directive | Script | Knowledge |
|---|---|---|---|
run |
Returns parsed XML content | Executes in venv with params | Returns entry content |
publish |
Creates version with content_hash | Uploads .py file with metadata | Publishes with tags |
link |
requires, suggests, extends |
depends_on, imports |
references, contradicts, extends |
Examples:
# Run a directive
execute(
item_type="directive",
action="run",
item_id="setup_auth",
parameters={"provider": "google"}
)
# Publish script to registry
execute(
item_type="script",
action="publish",
item_id="my_scraper",
parameters={"version": "1.0.0"}
)
# Delete with confirmation
execute(
item_type="knowledge",
action="delete",
item_id="001-old-entry",
parameters={"confirm": True}
)
help
Get usage guidance, examples, and troubleshooting.
Parameters:
topic(optional): Specific topic for help
Returns: JSON with help text
Examples:
# General help
help()
# Help for search tool
help(topic="search")
# Help for directive workflows
help(topic="directive")
Configuration
Environment Variables
# Supabase registry (optional)
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SECRET_KEY=your-secret-key
# User space directory (optional, defaults to ~/.ai if not provided)
# Set this in your MCP client configuration (e.g., Cursor's mcp.json)
# If not provided, defaults to ~/.ai
USER_SPACE=~/.ai
# Log level
LOG_LEVEL=INFO
Note: USER_SPACE is typically provided via your MCP client configuration (e.g., Cursor's mcp.json). If not set, it defaults to ~/.ai.
.env Files
Environment variables can be loaded from hierarchical .env files:
# Userspace defaults (applies to all projects)
~/.ai/.env
# Project-specific overrides
.ai/.env
Scripts automatically load both files in order (userspace → project → runtime).
Script Execution Features
Virtual Environment Isolation
Scripts run in isolated virtual environments:
- Project scripts:
.ai/scripts/.venv/ - Userspace scripts:
~/.ai/.venv/
Each environment is automatically created and managed.
Dependency Auto-Install
Dependencies are automatically detected and installed:
- From script
importstatements - From lib module imports
- Supports version constraints
# Script automatically installs: requests, beautifulsoup4
import requests
from bs4 import BeautifulSoup
from lib.http_session import get_session # Also installs lib dependencies
Shared Libraries
Scripts can import from shared library modules:
# Project lib (priority)
from lib.project_utils import helper
# Userspace lib (fallback)
from lib.http_session import get_session
from lib.youtube_utils import extract_video_id
Library locations:
.ai/scripts/lib/(project)~/.ai/scripts/lib/(userspace)
Output Management
Large script outputs are automatically saved:
- Project:
.ai/outputs/scripts/{script_name}/ - Userspace:
~/.ai/outputs/scripts/{script_name}/ - Keeps last 10 outputs per script
- Auto-truncates MCP responses >1MB
Architecture
┌─────────────────────────────────────────────────────────────┐
│ MCP Server │
├──────────────┬──────────────┬──────────────┬────────────────┤
│ search │ load │ execute │ help │
└──────┬───────┴──────┬───────┴──────┬───────┴────────┬───────┘
│ │ │ │
└──────────────┴──────────────┴────────────────┘
TypeHandlerRegistry
┌──────────┬──────────┬──────────┐
│ │ │ │
Directive Script Knowledge (Future)
Handler Handler Handler
│ │ │
├──────────┼──────────┤
│ Local + Registry Storage
Project Structure
kiwi-mcp/
├── kiwi_mcp/
│ ├── __init__.py # Package
│ ├── server.py # MCP server entry
│ ├── tools/ # 4 unified tools
│ │ ├── base.py # BaseTool abstract class
│ │ ├── search.py # SearchTool
│ │ ├── load.py # LoadTool
│ │ ├── execute.py # ExecuteTool
│ │ └── help.py # HelpTool
│ ├── handlers/ # Type-specific handlers
│ │ ├── registry.py # TypeHandlerRegistry
│ │ ├── directive/ # Directive handlers
│ │ ├── script/ # Script handlers
│ │ └── knowledge/ # Knowledge handlers
│ ├── api/ # Registry clients
│ │ ├── directive_registry.py
│ │ ├── script_registry.py
│ │ └── knowledge_registry.py
│ └── utils/ # Shared utilities
├── tests/
│ ├── unit/
│ │ ├── test_tools.py # Tool tests (20+)
│ │ └── test_handlers.py # Handler tests (20+)
│ └── integration/
├── docs/ # Documentation
├── README.md # This file
├── pytest.ini
└── pyproject.toml
Testing
Run All Tests
pytest tests/ -v
Run Unit Tests Only
pytest tests/unit/ -v
Coverage Report
pytest tests/ -v --cov=kiwi_mcp --cov-report=html
# Open htmlcov/index.html
Coverage Target
- Goal: >85% code coverage
- Current: 30% (tests in progress)
Development
Install Dev Dependencies
pip install -e ".[dev]"
Code Quality
# Linting
ruff check kiwi_mcp/
# Format
ruff format kiwi_mcp/
# Type checking
mypy kiwi_mcp/ --ignore-missing-imports
Running Locally
# Development server
python -m kiwi_mcp.server
# Or with auto-reload
pytest-watch tests/
API Reference
Item Types
directive
- Location:
.ai/directives/(project) or~/.ai/directives/(user) - Format: Markdown with YAML frontmatter
- Operations: search, load, run, publish, delete, create, update
script
- Location:
.ai/scripts/(project) or~/.ai/scripts/(user) - Format: Python (.py)
- Operations: search, load, run, publish, delete
- Features: venv isolation, auto-install dependencies, lib imports, .env loading
knowledge
- Location:
.ai/knowledge/(project) or~/.ai/knowledge/(user) - Format: Markdown with metadata
- Operations: search, load, create, update, delete, link, publish
Sources
- local - Search only in
.ai/directories - registry - Search only in Supabase registry
- all - Search both local and registry (registry items marked separately)
Error Handling
All tools return consistent error responses:
{
"error": "Description of what went wrong",
"item_type": "directive",
"message": "Human-readable message"
}
Troubleshooting
Import Errors
from kiwi_mcp import KiwiMCP
from kiwi_mcp.server import main
If imports fail:
- Check Python version:
python --version(need ≥3.11) - Reinstall:
pip install -e .
No Supabase Connection
If registry is unavailable, local operations still work:
- Search: Use
source="local" - Load: Downloads from registry disabled
- Execute: Local operations only
Slow Search
- Use
limitparameter to reduce results - Add more specific keywords
- Filter by category/tags (see handler docs)
Contributing
- Write tests first
- Implement feature
- Run:
pytest tests/ -v --cov=kiwi_mcp - Check coverage >85%
- Lint:
ruff check kiwi_mcp/
License
MIT License - see LICENSE file
Support
- Documentation:
docs/ARCHITECTURE.md,docs/API.md - Examples: See quick start above
- Issues: GitHub issues
Roadmap
- [ ] GraphQL registry queries
- [ ] Authentication/authorization
- [ ] Webhooks and real-time updates
- [ ] Web UI for management
- [ ] Plugin system for custom handlers
- [ ] Vector search with RAG
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器