Skip to content

Commit aaf2ceb

Browse files
Gl/add config improve decorator (#13)
* add config and improve decorator * update unit tests folder * fix lint
1 parent 92b21b8 commit aaf2ceb

47 files changed

Lines changed: 1933 additions & 1750 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,82 @@ uv run ruff check
2626
# Type checking
2727
uv run mypy src/
2828

29+
# Pre-commit hooks
30+
uv run pre-commit run --all-files
31+
2932
# Docker
3033
docker compose up --build
3134
```
3235

3336
## Architecture
3437

35-
HuMCP is a FastMCP server with a FastAPI adapter that exposes MCP tools as REST endpoints.
38+
HuMCP exposes tools via both MCP (Model Context Protocol) at `/mcp` and REST at `/tools/*`.
3639

37-
### Core Components
40+
### Core Library (`src/humcp/`)
3841

39-
**Entry Points:**
40-
- `src/main.py` - FastAPI application that mounts MCP at `/mcp` and auto-generates REST endpoints
41-
- `src/mcp_register.py` - Creates the FastMCP server, auto-discovers and registers tools from `src/tools/`
42+
- **`server.py`** - `create_app()` creates FastAPI app, loads tool modules, registers with FastMCP
43+
- **`decorator.py`** - `@tool(category="...")` marks functions for discovery. Category auto-detects from parent folder if not specified. Tool name = function name (used by FastMCP)
44+
- **`registry.py`** - `RegisteredTool` NamedTuple wraps FastMCP's `FunctionTool` with category
45+
- **`routes.py`** - Generates REST endpoints from registered tools using `FunctionTool.parameters`
46+
- **`config.py`** - Tool filtering via `config/tools.yaml` (include/exclude with wildcard support)
47+
- **`skills.py`** - Discovers `SKILL.md` files for category metadata
48+
- **`schemas.py`** - Pydantic response models for API endpoints
4249

43-
**Adapter Layer (`src/adapter/`):**
44-
- `fast_mcp_fast_api_adapter.py` - `FastMCPFastAPIAdapter` bridges FastMCP and FastAPI
45-
- `routes.py` - `RouteGenerator` creates REST endpoints from MCP tool schemas
46-
- `models.py` - Dynamically generates Pydantic models from MCP tool input schemas
50+
### Tool Discovery Flow
4751

48-
**Tool Registration System:**
49-
- Tools use `@tool(name, category)` decorator from `src/tools/__init__.py`
50-
- Decorator adds tools to `TOOL_REGISTRY` for auto-discovery
51-
- `src/mcp_register.py` walks `src/tools/` modules and registers all decorated functions with FastMCP
52+
1. `create_app()` loads Python modules from `src/tools/` recursively
53+
2. Functions with `@tool()` decorator are discovered via `_humcp_tool` attribute
54+
3. Each tool is registered with FastMCP via `mcp.tool()(func)` which creates a `FunctionTool`
55+
4. `RegisteredTool(tool=fn_tool, category=...)` pairs the FunctionTool with its category
56+
5. REST routes are generated from `FunctionTool.parameters` (JSON Schema)
5257

5358
### Adding New Tools
5459

55-
1. Create a `.py` file anywhere under `src/tools/` (no `__init__.py` required)
56-
2. Import and use the `@tool` decorator:
60+
Create a `.py` file in `src/tools/<category>/`:
61+
5762
```python
58-
from src.tools import tool
63+
from src.humcp.decorator import tool
5964

60-
@tool("my_tool_name")
65+
@tool() # category auto-detected from folder name
6166
async def my_tool(param: str) -> dict:
62-
"""Tool description."""
63-
return {"success": True, "data": result}
67+
"""Tool description (used by FastMCP and Swagger)."""
68+
return {"success": True, "data": {"result": param}}
69+
```
70+
71+
The function name becomes the tool name. Tools are auto-discovered on server startup.
72+
73+
### Response Pattern
74+
75+
```python
76+
# Success
77+
return {"success": True, "data": {...}}
78+
79+
# Error
80+
return {"success": False, "error": "Error message"}
6481
```
65-
3. Tools are auto-discovered on server startup via filesystem scan - no manual registration needed
6682

67-
### Tool Response Pattern
83+
### Skills
84+
85+
Add `SKILL.md` in tool category folders with YAML frontmatter:
86+
87+
```markdown
88+
---
89+
name: skill-name
90+
description: When and how to use these tools
91+
---
92+
# Content for AI assistants
93+
```
94+
95+
### Tool Configuration
96+
97+
`config/tools.yaml` controls which tools are exposed:
98+
99+
```yaml
100+
include:
101+
categories: [local, data]
102+
tools: [tavily_web_search]
103+
exclude:
104+
tools: [shell_*] # wildcards supported
105+
```
68106
69-
Tools return `{"success": True, "data": ...}` or `{"success": False, "error": "..."}`.
107+
Empty config = load all tools.

0 commit comments

Comments
 (0)