Enable MCP for all API endpoints#160
Enable MCP for all API endpoints#160R1ckyH wants to merge 7 commits intoblacklanternsecurity:devfrom
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
Add mcp=True to 38 remaining endpoints across 10 modules. Only WebSocket endpoints (agent dock, event/activity tail, event ingest) are excluded as they use a different protocol incompatible with MCP. Newly enabled endpoints by module: - agents: create_agent, delete_agent, get_agent, get_scan_status - activity: list_activities, query_activities, count_activities - assets: query_assets, count_assets - emails: get_emails - events: insert_event, get_event, list_events, query_events, count_events, archive_old_events - findings: query_findings, count_findings, set_risk - presets: create_preset, update_preset, delete_preset - scans: get_scans, query_scans, count_scans, cancel_scan - targets: count_targets, set_default_target, create_target, update_target, copy_target, delete_target, is_blacklisted, query_targets, list_ids - technologies: list_technologies, query_technologies, count_technologies Total MCP coverage: 69/73 (94.5%)
|
@R1ckyH thanks for the PR! Have you got a chance to test these out? Do they behave well? |
I am doing some tests on it, currently not yet finished all, but I think MCP is just another way to call the http api. |
fastapi-mcp 0.3.3 only forwarded the Authorization header, causing 401 errors when using custom auth headers like X-API-Key. Upgrade to 0.4.0 which adds a headers allowlist parameter, and pass ["x-api-key"] to forward the API key from MCP client requests to internal API calls. Co-Authored-By: R1ckyH <R1ckyH@users.noreply.github.com>
|
@TheTechromancer, I have added a new commit. This should fix the MCP API key issue mentioned in the README. |
|
I have also added some bug fixes here |
…rror HTTPStreamRoute's wrapper used @functools.wraps(), which copies attributes like __wrapped__ and __annotations__ from the original async generator function onto the wrapper. This caused FastAPI to detect the wrapper as an async generator and attempt to serialize its output via orjson.dumps(), resulting in: TypeError: Type is not JSON serializable: async_generator The wrapper is NOT an async generator — it's a regular async def that returns a StreamingResponse. Replace @functools.wraps with manual __name__, __qualname__, and __signature__ copying to give FastAPI the metadata it needs for routing without the async generator markers. This fixes streaming endpoints (list_assets, list_scans, etc.) for both direct HTTP access and MCP tool calls via fastapi_mcp.
ca927c1 — Fix streaming endpoints crashing with
|
…pe checks - Add None guards to all query_* endpoints (query_scans, query_assets, query_events, query_findings, query_targets, query_technologies) matching the pattern already applied to count_* endpoints - Fix get_emails: AssetFields now inherits CustomAssetFields so the emails field is properly registered on the Asset model, plus use getattr() fallback for safe attribute access - Fix count_activities/query_activities: make query parameter optional with ActivityQuery | None = None and add None guard - Fix in_scope/is_blacklisted/is_in_target: return False instead of crashing when no default target exists in the database All 45 testable MCP endpoints now pass (0 failures).
|
Hey @TheTechromancer, after testing the MCP endpoints against a live server with a full scan workflow (create target → start scan → agent runs → query results), I found a few issues. Wanted to flag before this goes further: 1.
|
|
One more thing to talk about here, when I am trying to do the MCP testing, I face many issues, such as the function not yet implemented. I want to know your attitude before I continue. |
Summary
mcp=Trueto 38 remaining API endpoints across 10 modulesNew MCP endpoints by module
create_agent,delete_agent,get_agent,get_scan_statuslist_activities,query_activities,count_activitiesquery_assets,count_assetsget_emailsinsert_event,get_event,list_events,query_events,count_events,archive_old_eventsquery_findings,count_findings,set_riskcreate_preset,update_preset,delete_presetget_scans,query_scans,count_scans,cancel_scancount_targets,set_default_target,create_target,update_target,copy_target,delete_target,is_blacklisted,query_targets,list_idslist_technologies,query_technologies,count_technologies