Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
Cleanup
Prateek6bce5fd5083a
diff --git a/python/composio/integration_test/test_mcp_workflow_demo.py b/python/composio/integration_test/test_mcp_workflow_demo.pydeleted file mode 100644index c125a6eb5..000000000--- a/python/composio/integration_test/test_mcp_workflow_demo.py+++ /dev/null@@ -1,201 +0,0 @@-#!/usr/bin/env python3-"""-MCP Workflow Demo - Complete end-to-end test.--This script demonstrates a complete MCP workflow:-1. Create MCP server with composio_search and text_to_pdf toolkits-2. Generate server instance for a user-3. Connect to the MCP server-4. Use the tools through MCP protocol-5. Demonstrate real tool execution-"""--import os-import time-import json-import requests-from composio import Composio--def create_mcp_server_with_tools():- """Create MCP server with search and PDF tools."""-- composio = Composio()-- server_name = f'demo-workflow-{int(time.time()) % 1000000}'-- print(f"ποΈ Creating MCP server: {server_name}")-- mcp_server = composio.experimental.mcp.create(server_name, {- 'toolkits': [- {- 'toolkit': 'composio_search',- 'allowed_tools': ['COMPOSIO_SEARCH_DUCK_DUCK_GO_SEARCH']- },- {- 'toolkit': 'text_to_pdf',- 'allowed_tools': ['TEXT_TO_PDF_CONVERT_TEXT_TO_PDF']- }- ],- 'manually_manage_connections': False- })-- print(f"β MCP server created!")- print(f" Server ID: {mcp_server.id}")- print(f" Available Tools: COMPOSIO_SEARCH_DUCK_DUCK_GO_SEARCH, TEXT_TO_PDF_CONVERT_TEXT_TO_PDF")-- return mcp_server--def generate_user_instance(mcp_server, user_id):- """Generate MCP server instance for a specific user."""-- print(f"\nπ€ Generating server instance for user: {user_id}")-- server_instance = mcp_server.generate(user_id)-- print(f"β Server instance generated!")- print(f" Instance URL: {server_instance['url']}")- print(f" Instance Type: {server_instance['type']}")- print(f" User ID: {server_instance['user_id']}")-- return server_instance--def test_mcp_server_connectivity(server_instance):- """Test basic connectivity to the MCP server."""-- print(f"\nπ Testing MCP server connectivity...")-- mcp_url = server_instance['url']-- try:- headers = {- 'Accept': 'text/event-stream, application/json, */*',- 'Cache-Control': 'no-cache',- 'User-Agent': 'Composio-MCP-Demo'- }-- response = requests.get(mcp_url, headers=headers, timeout=10, stream=True)-- if response.status_code == 200:- print(f"β MCP server is accessible!")- print(f" Status: {response.status_code}")- print(f" Content-Type: {response.headers.get('Content-Type')}")-- # Read first few events- events = []- for i, chunk in enumerate(response.iter_content(chunk_size=1024, decode_unicode=True)):- if chunk.strip():- events.append(chunk.strip())- if i >= 2: # Read first few chunks- break-- print(f" Initial Events: {len(events)} events received")- for j, event in enumerate(events[:2]):- print(f" Event {j+1}: {event[:80]}...")-- return True- else:- print(f"β MCP server returned status: {response.status_code}")- return False-- except requests.exceptions.Timeout:- print(f"β οΈ Connection timeout (normal for SSE endpoints)")- return True # Timeout is actually expected for SSE- except Exception as e:- print(f"β Connection failed: {e}")- return False--def demonstrate_tool_availability(server_instance):- """Demonstrate that tools are available through the MCP server."""-- print(f"\nπ οΈ Tool Availability Check:")-- tools = server_instance.get('allowed_tools', [])- print(f" Available Tools: {len(tools)}")-- for i, tool in enumerate(tools, 1):- print(f" {i}. {tool}")-- # Describe what each tool does- if 'DUCK_DUCK_GO_SEARCH' in tool:- print(f" π Performs web searches using DuckDuckGo")- elif 'TEXT_TO_PDF' in tool:- print(f" π Converts text content to PDF format")-- return len(tools) > 0--def demonstrate_mcp_usage_example():- """Show how the MCP server would be used in practice."""-- print(f"\nπ‘ MCP Usage Example:")- print(f" Once connected to the MCP server, you could:")- print(f" ")- print(f" 1. π Search for information:")- print(f" Tool: COMPOSIO_SEARCH_DUCK_DUCK_GO_SEARCH")- print(f" Input: {{'query': 'Python MCP protocol'}}")- print(f" Output: Search results with titles, snippets, and URLs")- print(f" ")- print(f" 2. π Convert search results to PDF:")- print(f" Tool: TEXT_TO_PDF_CONVERT_TEXT_TO_PDF")- print(f" Input: {{'text': 'Search results content...'}}")- print(f" Output: PDF file with the content")- print(f" ")- print(f" π Complete workflow:")- print(f" Search β Extract content β Convert to PDF β Save/Share")--def main():- """Main demo function."""-- # Check API key- api_key = os.getenv('COMPOSIO_API_KEY')- if not api_key:- print("β COMPOSIO_API_KEY environment variable not set")- return False-- print("π― MCP Workflow Demo")- print("=" * 50)- print("Demonstrating complete MCP workflow with composio_search and text_to_pdf")- print()-- try:- # Step 1: Create MCP server- mcp_server = create_mcp_server_with_tools()-- # Step 2: Generate user instance- user_id = f'demo_user_{int(time.time()) % 10000}'- server_instance = generate_user_instance(mcp_server, user_id)-- # Step 3: Test connectivity- connectivity_ok = test_mcp_server_connectivity(server_instance)-- # Step 4: Check tool availability- tools_available = demonstrate_tool_availability(server_instance)-- # Step 5: Show usage examples- demonstrate_mcp_usage_example()-- # Summary- print(f"\nπ Demo Summary:")- print(f" β MCP Server Created: {mcp_server.id}")- print(f" β User Instance Generated: {server_instance['user_id']}")- print(f" β Server Connectivity: {'Working' if connectivity_ok else 'Failed'}")- print(f" β Tools Available: {len(server_instance.get('allowed_tools', []))} tools")- print(f" β Auth Required: {'No' if not server_instance.get('auth_configs') else 'Yes'}")- print(f" β Server Type: {server_instance['type']}")-- print(f"\nπ MCP Workflow Demo Complete!")- print(f" Your MCP server is ready to use at:")- print(f" {server_instance['url']}")- print(f" ")- print(f" Connect your MCP client to this URL to start using the tools!")-- return True-- except Exception as e:- print(f"β Demo failed: {e}")- import traceback- traceback.print_exc()- return False--if __name__ == "__main__":- main()-