Skip to content

Commit 5b22038

Browse files
committed
Fix n8n tool call bug: Add **kwargs support to search.py, datasources.py, and chat.py functions for enhanced flexibility.
1 parent 5064382 commit 5b22038

File tree

13 files changed

+1759
-203
lines changed

13 files changed

+1759
-203
lines changed

CLAUDE.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,47 @@ docker build -t codealive-mcp .
4141
docker run --rm -i -e CODEALIVE_API_KEY=your_key_here codealive-mcp
4242
```
4343

44+
### Testing
45+
46+
#### Quick Smoke Test
47+
After making local changes, quickly verify everything works:
48+
```bash
49+
# Using make (recommended)
50+
make smoke-test
51+
52+
# Or directly
53+
python smoke_test.py
54+
55+
# With valid API key for full testing
56+
CODEALIVE_API_KEY=your_key python smoke_test.py
57+
```
58+
59+
The smoke test:
60+
- ✓ Verifies server starts and connects via stdio
61+
- ✓ Checks all tools are registered correctly
62+
- ✓ Tests each tool responds appropriately
63+
- ✓ Validates parameter handling
64+
- ✓ Runs in ~5 seconds
65+
66+
#### Unit Tests
67+
Run comprehensive unit tests with pytest:
68+
```bash
69+
# Using make
70+
make unit-test
71+
72+
# Or directly
73+
pytest src/tests/ -v
74+
75+
# With coverage
76+
pytest src/tests/ -v --cov=src
77+
```
78+
79+
#### All Tests
80+
Run both smoke tests and unit tests:
81+
```bash
82+
make test
83+
```
84+
4485
## Architecture
4586

4687
This is a Model Context Protocol (MCP) server that provides AI clients with access to CodeAlive's semantic code search and analysis capabilities.
@@ -59,6 +100,7 @@ This is a Model Context Protocol (MCP) server that provides AI clients with acce
59100
3. **Streaming Support**: Implements streaming chat completions with proper chunk parsing
60101
4. **Environment Configuration**: Supports both .env files and command-line arguments with precedence
61102
5. **Error Handling**: Comprehensive HTTP status code handling with user-friendly error messages
103+
6. **N8N Middleware**: Strips extra parameters (sessionId, action, chatInput, toolCallId) from n8n tool calls before validation
62104

63105
### Data Flow
64106

@@ -87,9 +129,12 @@ The server is designed to integrate with:
87129
- Cursor (via MCP settings panel)
88130
- VS Code with GitHub Copilot (via settings.json)
89131
- Continue (via config.yaml)
132+
- n8n (via AI Agent node with MCP tools)
90133
- Any MCP-compatible AI client
91134

92-
Key integration consideration: AI clients should use `get_data_sources` first to discover available repositories/workspaces, then use those IDs for targeted search and chat operations.
135+
Key integration considerations:
136+
- AI clients should use `get_data_sources` first to discover available repositories/workspaces, then use those IDs for targeted search and chat operations
137+
- **n8n Integration**: The server includes middleware to automatically strip n8n's extra parameters (sessionId, action, chatInput, toolCallId) from tool calls, so n8n works out of the box without any special configuration
93138

94139
## Publishing and Releases
95140

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.PHONY: help install test smoke-test unit-test clean run dev
2+
3+
help: ## Show this help message
4+
@echo "Available commands:"
5+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
6+
7+
install: ## Install dependencies
8+
uv pip install -e ".[test]"
9+
10+
smoke-test: ## Run smoke tests (quick sanity check)
11+
@echo "Running smoke tests..."
12+
python smoke_test.py
13+
14+
unit-test: ## Run unit tests with pytest
15+
@echo "Running unit tests..."
16+
pytest src/tests/ -v
17+
18+
test: unit-test smoke-test ## Run all tests (unit + smoke)
19+
20+
clean: ## Clean up cache and temp files
21+
rm -rf __pycache__
22+
rm -rf .pytest_cache
23+
rm -rf src/__pycache__
24+
rm -rf src/tests/__pycache__
25+
rm -rf *.pyc
26+
rm -rf src/*.pyc
27+
rm -rf .coverage
28+
rm -rf htmlcov
29+
30+
run: ## Run the MCP server with stdio transport
31+
python src/codealive_mcp_server.py
32+
33+
dev: ## Run the MCP server in debug mode
34+
python src/codealive_mcp_server.py --debug

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
**Connect your AI assistant to CodeAlive's powerful code understanding platform in seconds!**
88

9-
This MCP (Model Context Protocol) server enables AI clients like Claude Code, Cursor, Claude Desktop, Continue, VS Code (GitHub Copilot), Cline, Codex, OpenCode, Qwen Code, Gemini CLI, Roo Code, Goose, Kilo Code, Windsurf, Kiro, Qoder, and Amazon Q Developer to access CodeAlive's advanced semantic code search and codebase interaction features.
9+
This MCP (Model Context Protocol) server enables AI clients like Claude Code, Cursor, Claude Desktop, Continue, VS Code (GitHub Copilot), Cline, Codex, OpenCode, Qwen Code, Gemini CLI, Roo Code, Goose, Kilo Code, Windsurf, Kiro, Qoder, n8n, and Amazon Q Developer to access CodeAlive's advanced semantic code search and codebase interaction features.
1010

1111
## What is CodeAlive?
1212

@@ -749,6 +749,33 @@ See [JetBrains MCP Documentation](https://www.jetbrains.com/help/ai-assistant/mc
749749

750750
</details>
751751

752+
<details>
753+
<summary><b>n8n</b></summary>
754+
755+
**Using AI Agent Node with MCP Tools**
756+
757+
1. Add an **AI Agent** node to your workflow
758+
2. Configure the agent with MCP tools:
759+
```
760+
Server URL: https://mcp.codealive.ai/api
761+
Authorization Header: Bearer YOUR_API_KEY_HERE
762+
```
763+
764+
3. The server automatically handles n8n's extra parameters (sessionId, action, chatInput, toolCallId)
765+
4. Use the three available tools:
766+
- `get_data_sources` - List available repositories
767+
- `codebase_search` - Search code semantically
768+
- `codebase_consultant` - Ask questions about code
769+
770+
**Example Workflow:**
771+
```
772+
Trigger → AI Agent (with CodeAlive MCP tools) → Process Response
773+
```
774+
775+
**Note:** n8n middleware is built-in, so no special configuration is needed. The server will automatically strip n8n's extra parameters before processing tool calls.
776+
777+
</details>
778+
752779
---
753780
754781
## 🔧 Advanced: Local Development
@@ -810,6 +837,34 @@ python src/codealive_mcp_server.py --transport http --host localhost --port 8000
810837
curl http://localhost:8000/health
811838
```
812839

840+
### Testing Your Local Installation
841+
842+
After making changes, quickly verify everything works:
843+
844+
```bash
845+
# Quick smoke test (recommended)
846+
make smoke-test
847+
848+
# Or run directly
849+
python smoke_test.py
850+
851+
# With your API key for full testing
852+
CODEALIVE_API_KEY=your_key python smoke_test.py
853+
854+
# Run unit tests
855+
make unit-test
856+
857+
# Run all tests
858+
make test
859+
```
860+
861+
The smoke test verifies:
862+
- Server starts and connects correctly
863+
- All tools are registered
864+
- Each tool responds appropriately
865+
- Parameter validation works
866+
- Runs in ~5 seconds
867+
813868
### Smithery Installation
814869

815870
Auto-install for Claude Desktop via [Smithery](https://smithery.ai/server/@CodeAlive-AI/codealive-mcp):

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ description = "MCP server for the CodeAlive API"
55
readme = "README.md"
66
requires-python = ">=3.11"
77
dependencies = [
8-
"fastmcp==2.12.3",
8+
"fastmcp==2.13.0.2",
99
"httpx==0.28.1",
1010
"python-dotenv==1.1.1",
1111
]
1212

1313
[project.optional-dependencies]
1414
test = [
15-
"pytest==8.3.6",
16-
"pytest-asyncio==0.25.2",
17-
"pytest-mock==3.15.0",
18-
"pytest-cov==6.0.0",
15+
"pytest>=8.0.0,<9.0.0",
16+
"pytest-asyncio>=0.23.0,<1.0.0",
17+
"pytest-mock>=3.14.0,<4.0.0",
18+
"pytest-cov>=4.0.0,<6.0.0",
19+
"mcp>=1.0.0",
1920
]
2021

2122
[project.scripts]

0 commit comments

Comments
 (0)