diff --git a/deployed-agents/python/README.md b/deployed-agents/python/README.md index 0a4fd29..4a427fd 100644 --- a/deployed-agents/python/README.md +++ b/deployed-agents/python/README.md @@ -1,26 +1,13 @@ -# 🐍 Corvic AI Python Integration Example +# 🐍 Corvic AI Python Integration Example using MCP (HTTP Streamable) -This example demonstrates how to use the Corvic AI MCP protocol in Python to query a deployed agent that processes PDF-based enterprise data. +This example demonstrates how to use the Corvic AI MCP (HTTP) protocol in Python to query a deployed agent that processes PDF-based enterprise data. --- -## πŸ“˜ Use Case - -We will ask a question that requires the Corvic agent to look up and reason through a NAICS (North American Industry Classification System) PDF document. - ---- - -## βœ… Prerequisites - -1. Complete the setup steps in this [blog post](https://corvic.substack.com/p/automating-address-updates-with-corvic?open=false#%C2%A7the-corvic-solution-automation-without-overhead). -2. Upload the [NAICS 2022 Manual PDF](https://www.census.gov/naics/reference_files_tools/2022_NAICS_Manual.pdf) and deploy your agent on Corvic’s platform. -3. Once deployed, copy the MCP endpoint and access token. - ---- ## 🧰 Integration Steps -1. Use the `mcp` Python package to create an `sse_client` connection to the deployed agent. +1. Use the `mcp` Python package to create an `streamablehttp_client` connection to the deployed agent. 2. Pass the MCP endpoint and your API token in the request headers. 3. Initialize the session and retrieve the list of available tools (Corvic currently supports a single tool: `query`). 4. Call the `query` tool with your question via the `query_content` argument. @@ -31,23 +18,20 @@ We will ask a question that requires the Corvic agent to look up and reason thro ## 🧠 Question Asked ```text -Map the NAICS code 441228 from 2017 to the 2022 NAICS code. +What is the MPG for Valiant? ``` ## πŸ“€ Response -The response will look as below. The mapping as well as the relevant section of the document is retrieved by the Corvic agent. - -![NAICS Mapping Result](../../assets/images/python_readme_naics_output.png) +The response will look as below. +The MPG for Valiant is 18 --- ## πŸ“„ Notes - The `query_content` argument is **required**. -- Replace the placeholder token with your actual Corvic API token. -- You can save or manipulate the response as needed (e.g., convert to HTML, display in UI, etc). - +- Replace the placeholder token with your actual Corvic API token and Agent URI. --- Need help? Contact [support@corvic.ai](mailto:support@corvic.ai) or visit [https://www.corvic.ai](https://www.corvic.ai). diff --git a/deployed-agents/python/python-integration-example.py b/deployed-agents/python/python-integration-example.py index 8a62f32..2d66e0a 100644 --- a/deployed-agents/python/python-integration-example.py +++ b/deployed-agents/python/python-integration-example.py @@ -1,30 +1,29 @@ import asyncio from mcp import ClientSession -from mcp.client.sse import sse_client +from mcp.client.streamable_http import streamablehttp_client + async def run(): - async with sse_client( - "", # Replace with your deployed agent's endpoint - headers={ - "Authorization": "" # Replace with your API token - }, - ) as (read, write): + url = "" + headers = { + "Content-Type": "application/json", + "Accept": "application/json, text/event-stream", + "Authorization": "" + } + async with streamablehttp_client(url=url, headers=headers) as (read, write, session_id): async with ClientSession(read, write) as session: - # Initialize the connection - await session.initialize() - - # List available tools tools = await session.list_tools() print(tools) - # Call a tool result = await session.call_tool( - "query", arguments={"query_content": "Map the NAICS code 441228 from 2017 to the 2022 NAICS code."} + "query", arguments={"query_content": "What is the MPG for Valiant?"} ) - # Save results to Markdown - with open("naics_query.md", "a") as file: - for content in result.content: - file.write(content.text) + all_content = '' + for content in result.content: + all_content += content.text + print(content.text) + return all_content + if __name__ == "__main__": asyncio.run(run())