Commit Graph

322 Commits

Author SHA1 Message Date
Hemang 05e09331e9 Address comments on PR and update README. 2025-06-04 11:46:35 +02:00
Hemang cc3e96c20a Clean up MCP tests and clients. 2025-06-04 11:46:35 +02:00
Hemang f6ba31ab2e Move util methods to MCPTransportBase. 2025-06-04 11:46:35 +02:00
Hemang 7ec13ad852 Create StreamableTransport class for MCP Streamable http transport. This subclasses MCPTransportBase. 2025-06-04 11:46:35 +02:00
Hemang 2e6f669923 Create SSETransport class for MCP SSE transport. This subclasses MCPTransportBase. 2025-06-04 11:46:35 +02:00
Hemang 7efd15e2a9 Move MCP related routes to the MCP directory and introduce the MCPTransportBase class. 2025-06-04 11:46:35 +02:00
Hemang e8106776b4 Refactor stdio implementation to use McpSession class. 2025-06-04 11:46:35 +02:00
Hemang 6849fc7daa Update McpSession class so that it can be used from both sse/streamable and stdio transports. Also update SseHeaderAttributes to McpAttributes so that it be can be used different MCP transports. 2025-06-04 11:46:35 +02:00
Hemang 96826fa06d Cleanup some code in test_mcp.py 2025-05-27 23:11:57 +02:00
Hemang bfb57029e6 Small cleanups. 2025-05-27 23:11:57 +02:00
Hemang ab3fb98b67 Add blocking and logging related tests for MCP streamable HTTP route. 2025-05-27 23:11:57 +02:00
Hemang 115ae5f36b Add tests for MCP streamable HTTP route for json/sse and stateless/stateful servers. 2025-05-27 23:11:57 +02:00
Hemang 34979ed18d Move hook_tool_call and hook_tool_call_response to mcp_utils.py so that it can be used by both SSE and Streamable implementations. 2025-05-27 23:11:57 +02:00
Hemang 6e61a76168 Add blocking and logging of guardrails for MCP Streamable http route. 2025-05-27 23:11:57 +02:00
Hemang 20adc7804b Accep the invariant api key in the header for sse gateway and use it for guardrailing and pushing to explorer. 2025-05-27 23:11:57 +02:00
Hemang 71e2ac9a06 Add implementation for MCP streamable GET, POST and DELETE endpoints without push to explorer or guardrailing. 2025-05-27 23:11:57 +02:00
Hemang f8bf7be405 Add mcp_streamable route and refactor some common code between sse and streamable. Update tests for 400 errors in sse. 2025-05-27 23:11:57 +02:00
Hemang 5b68e80be5 Add MCP client and server name when calling fetch_guardrails_from_explorer in SSE. 2025-05-22 10:29:59 +02:00
Hemang 03817b005c Update metadata in MCP SSE similar to what we do in MCP stdio. 2025-05-21 22:45:59 +02:00
Luca Beurer-Kellner 177d247a83 Update pyproject.toml 2025-05-21 16:46:43 +02:00
Luca Beurer-Kellner 04d0b70c48 use metadata client to fetch policies 2025-05-21 16:28:06 +02:00
Hemang 169eb066b9 Small cleanups in sse and stdio MCP implementation. 2025-05-21 15:58:22 +02:00
Luca Beurer-Kellner 418c873e04 Update pyproject.toml 2025-05-21 10:05:48 +02:00
Luca Beurer-Kellner c1112b91fc use windows select (#56)
* use windows select

* factor out platform-specific stdin waiting
2025-05-21 09:43:00 +02:00
Luca Beurer-Kellner 2060f18b0a Update pyproject.toml 2025-05-19 14:22:56 +02:00
Luca Beurer-Kellner e18c6b5bdb Add an option to add extra metadata that is pushed and passed to Guardrails during an MCP session (#47)
* use select() before readline

* support for setting static metadata for MCP sessions

* nest extra mcp metadata in metadata object

* unify session metadata

* extra metadata tests

* use empty object as parameters, if None

* list_tools as tool call

* offset indices in tests

* test: adjust addresses

* mcp: make error reporting configurable

* line logging

* log version

* verbose logging + loud exception failure

* add server and client name to policy get

* append trace even if not pushing

* port tools/list message support to SSE

* use python -m build

* adjust guardrail failure address

* support for blocking tools/list in SSE

* use error-based failure response format by default

* tools/list test

* don't list_tools in stdio connect

* flaky test: handle second possible result in anthropic streaming case

---------

Co-authored-by: knielsen404 <kristian@invariantlabs.ai>
2025-05-19 13:44:37 +02:00
Hemang 4dbb400620 Move invariant api key check to __main__.py so that the same check can work for both mcp and server commands. 2025-05-16 14:33:00 +05:30
Hemang f33b2392f6 Fix the Dockerfle for gateway to copy correctly. 2025-05-16 14:33:00 +05:30
Hemang 780e5f6ee7 Skip test_generate_content_with_image for gemini. Getting 500. 2025-05-16 14:33:00 +05:30
Hemang 876eb44c78 Make MCP stdio gateway fully async. With sync and async mixed behaviour for running background tasks we were running into issues. 2025-05-16 14:33:00 +05:30
Hemang Sarkar a6c1124076 Update test_mcp.py 2025-05-15 15:00:31 +05:30
Hemang Sarkar 0ffde69391 Fix test_mcp_sse_with_gateway_hybrid_guardrails so that we don't rely on order of annotations. 2025-05-15 15:00:31 +05:30
Hemang a214837b1e Add message to session store for MCP sse in post path before returning. 2025-05-14 15:44:52 +02:00
Hemang Sarkar fefc22eea0 Update test_mcp.py to include the transport parameter in the hybrid guardrails test. 2025-05-14 15:32:05 +02:00
Hemang e32ec74ed2 Fix paths to pyproject.toml and README in dockerfile.gateway. Also update context in publish-images.yml 2025-05-14 18:05:14 +05:30
Hemang ed50670bef Add MCP gateway tests with hybrid guardrails (both blocking and logging). Also refactor tests so that we can parameterize the transport type - stdio or sse. 2025-05-14 18:05:14 +05:30
Hemang 8eae198eb0 Add integration tests for MCP SSE via gateway with guardrails. 2025-05-14 14:21:48 +05:30
Hemang e2e004b7b1 Move dockerfiles inside gateway/ and update main CLI script to be able to run build, up, down and logs on a local gateway server instance. 2025-05-14 14:21:48 +05:30
Hemang Sarkar 73de68e822 Update tests_ci.yml with a timeout at the job level. 2025-05-12 15:36:33 +02:00
Hemang dbab86e0ac Fix broken tests. 2025-05-09 12:17:14 +05:30
Hemang edd9fd9a5c When tool_call is blocked in MCP Post method, add the error message to a pending error messages list. Create two queues in the MCP SSE Get endpoint which correspond to the MCP server events and these pending error messages. These two queues are merged to return events back to the client. 2025-05-09 11:05:33 +05:30
Hemang 794aae0326 Add MCP guardrailing for SSE. 2025-05-08 20:40:28 +05:30
Hemang 40ec6d2db2 Add MCP SSE server proxying in gateway. 2025-05-08 14:11:22 +05:30
Hemang 132eedab0a Update tests_ci.yml so that the CI run fails even when unit tests fail. 2025-05-07 02:03:06 +05:30
Hemang d057aa5c37 Add httpx as unit test dependencies. 2025-05-07 01:27:13 +05:30
Hemang 1f6e2ed7fb Update streaming in anthropic route to handle chunks with incomplete events. Introduce an sse_buffer which keeps track of the current incomplete event from the last processed chunk. 2025-05-07 01:08:15 +05:30
Hemang aec7808e3e Fix broken integration tests. 2025-05-07 01:08:15 +05:30
Hemang dc9ac9c3c6 Fix broken unit tests. 2025-05-07 01:08:15 +05:30
Hemang e64a977d87 Properly propagate the integrations test and unit test exit code. 2025-05-06 20:10:45 +05:30
Luca Beurer-Kellner 86ec75ba2d use select() before readline (#45) 2025-05-06 16:07:50 +02:00