组件MCP服务器
一个简单的MCP服务器,提供列出和检索存储在中的可重用组件详细信息的工具 .libs 目录。
特性
此服务器提供 两个工具:
- 列表_组件:列出给定类型(应用程序或功能)的所有组件
- 获取详细信息:返回特定组件的详细信息
组件类型
组件根据其 index.yaml 文件:
- 函数:多个公共函数(index.yaml中有2+个条目)
- 具有多种可重用功能的库 - 每个函数都可以独立调用 - 示例:具有文本格式、数学运算等的实用程序库。
- 应用:单个主入口点(index.yaml中的1个入口)
- 具有主要功能的完整应用程序 - 子目录中的助手/私有模块 - 示例:带有一个main()函数的电子邮件应用程序,该函数处理所有操作
安装
选项1:使用uvx运行(无需安装)
使用服务器的最快方法:
# Run directly with uvx (from local directory)
uvx --from . components-mcp
# Or from a built package
uvx --from dist/components_mcp-0.1.0-py3-none-any.whl components-mcp
# Or from a Git repository
uvx --from git+https://github.com/your-org/components-mcp.git components-mcp选项2:本地安装
# Install with uv
uv sync
# Or with pip
pip install -e .用法
运行服务器
# METHOD 1: Run with uvx (recommended for quick use)
uvx --from . components-mcp
# METHOD 2: Run with FastMCP CLI
fastmcp run src/components_mcp/server.py
# METHOD 3: Run as installed command
uv run components-mcp
# METHOD 4: Run as Python module
python -m components_mcp
# Run with HTTP transport
fastmcp run src/components_mcp/server.py --transport http --port 8000
# Run with MCP Inspector for testing
fastmcp dev src/components_mcp/server.py在MCP客户端中安装
# Install in Claude Desktop
fastmcp install claude-desktop src/components_mcp/server.py
# Install in Claude Code
fastmcp install claude-code src/components_mcp/server.py
# Install in Cursor
fastmcp install cursor src/components_mcp/server.py组件目录发现
服务器扫描 .libs 目录按以下顺序排列:
- 本地项目:
./libs(当前工作目录) - 环境变量:
$COMPONENT_DIR/.libs - 默认缓存:
~/.cache/agent-tools/.libs
设置 COMPONENT_DIR 使用自定义位置的环境变量:
export COMPONENT_DIR=/path/to/components
fastmcp run server.py工具
1.列表_组件
列出.lbs目录中的组件。
参数:
type(可选):按类型筛选-"app","function",或省略列出所有内容
退货:
[
{
"name": "category.feature.function_name",
"description": "Brief description of the component"
}
]示例:
# List all components (apps + functions)
result = await client.call_tool(
name="list_components",
arguments={}
)
# List only functions
result = await client.call_tool(
name="list_components",
arguments={"type": "function"}
)
# List only apps
result = await client.call_tool(
name="list_components",
arguments={"type": "app"}
)2.获取详细信息
返回特定组件的详细信息。
参数:
type(必填):要么"app"或"function"name(必填):完全限定的组件名称(例如。,"category.feature.function")
退货:
{
"name": "category.feature.function_name",
"type": "function",
"description": "Full docstring from the component",
"short_description": "Brief description from index.yaml",
"module_path": "/path/to/.libs/category/feature/module.py",
"root_directory": "/path/to/.libs",
"category": "category",
"feature": "feature"
}例子:
# Get details for a specific component
result = await client.call_tool(
name="get_details",
arguments={
"type": "function",
"name": "utils.service_config.rename_service"
}
)测试
使用pytest运行测试套件:
# Install test dependencies
uv sync --group dev
# Run all tests
uv run pytest
# Run with verbose output
uv run pytest -v
# Run specific test file
uv run pytest tests/test_server.py -v
# Run with coverage
uv run pytest --cov=src/components_mcp项目结构
components-mcp/
├── src/
│ └── components_mcp/
│ ├── __init__.py
│ ├── __main__.py # Entry point
│ └── server.py # MCP server implementation
├── tests/
│ ├── __init__.py
│ ├── test_server.py # Server configuration tests
│ ├── test_list_components.py # list_components tool tests
│ └── test_get_details.py # get_details tool tests
├── .libs/ # Example component library
│ ├── index.yaml
│ └── example/
│ ├── utils/
│ └── email_app/
├── pyproject.toml
└── README.md组件目录结构
注: 没有根index.yaml文件。每个组件目录都有自己的index.yaml。
功能类型组件
组件与 多种公共职能 (索引yaml中有2个以上条目):
.libs/
└── category/
└── feature/ # Function component
├── __init__.py
├── index.yaml # Lists all public functions
├── module_1.py # Contains public function(s)
└── module_2.py # Contains public function(s)函数的示例index.yaml:
functions:
- name: category.feature.module_1.function_a
description: First public function
- name: category.feature.module_1.function_b
description: Second public function
- name: category.feature.module_2.function_c
description: Third public function应用程序类型组件
带有a的组件 单一主要入口点 (索引yaml中有1个条目):
.libs/
└── category/
└── app_name/ # App component
├── __init__.py
├── index.yaml # Lists only main function
├── main.py # Contains main() function
└── helpers/ # Private helper modules
├── __init__.py
├── helper_1.py
└── helper_2.py应用程序的index.yaml示例:
functions:
- name: category.app_name.main.main
description: Main entry point for the application配电楼
为uvx或PyPI构建可分发的包:
# Build wheel and source distribution
uv build
# Output will be in dist/
# - dist/components_mcp-0.1.0-py3-none-any.whl (wheel)
# - dist/components_mcp-0.1.0.tar.gz (source)
# Run from built wheel with uvx
uvx --from dist/components_mcp-0.1.0-py3-none-any.whl components-mcp
# Or install from wheel
pip install dist/components_mcp-0.1.0-py3-none-any.whl发展
# Run server with auto-reload during development
fastmcp dev src/components_mcp/server.py
# Inspect server components
fastmcp inspect src/components_mcp/server.py
# Generate JSON report
fastmcp inspect src/components_mcp/server.py --format fastmcp -o report.json
# Run tests during development
uv run pytest tests/ -v --tb=short
# Build package
uv build许可证
麻省理工学院
