Wrapping Corvic MCP with FastAPI for Web Integrations

This example demonstrates how to expose Corvic's MCP protocol through a FastAPI web endpoint. This makes it easy to integrate Corvic-powered agents into external services like Slack, Discord, webhooks, or custom UIs.


Use Case

You want to expose a Corvic agent to external clients (e.g., Slack command, customer service UI, webhooks) via a simple HTTP endpoint. This FastAPI app acts as a bridge between those services and Corvic's MCP-based query interface.


Key Points

  • The slack_handler (general-purpose POST endpoint) receives a user query via HTTP POST.
  • The process_query_and_respond method:
    • Initializes an sse_client connection to your deployed Corvic agent.
    • Sends a query_content to Corvic via the ClientSession.
    • Forwards the response to a webhook (e.g., response_url).
  • The response_url mechanism enables compatibility with asynchronous platforms like Slack or others expecting delayed responses.

The following code shows the relevant FastAPI configuration discussed above. You can incorporate it in your project as needed.

python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

Need help? Contact support@corvic.ai or visit https://www.corvic.ai.