MCPcopy Create free account
hub / github.com/InternScience/InternAgent / main

Function main

mcp_demo.py:171–290  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

169
170
171async def main():
172 print("\n" + "="*60)
173 print("MyAgent Demo - Function-based + MCP Tools")
174 print("="*60)
175
176 # Switch between different configs to test:
177 # - CONFIG: both local and remote tools
178 # - CONFIG_NO_LOCAL: only remote MCP tools
179 # - CONFIG_LOCAL_ONLY: only local function tools
180 active_config = CONFIG_LOCAL_ONLY # Change this to test different configurations
181
182 try:
183 # Step 1: Initialize tools from config
184 print("\n" + "="*60)
185 print("TOOL INITIALIZATION")
186 print("="*60)
187
188 tools_config = active_config.get("tools", {})
189
190 # Initialize local function-based tools if enabled
191 if tools_config.get("local", True):
192 print("\n[✓] Loading local function-based tools...")
193 init_tools()
194 print(" Local tools initialized successfully")
195 else:
196 print("\n[✗] Local tools DISABLED by configuration")
197
198 # Initialize remote MCP tools if configured
199 remote_servers = tools_config.get("remote", [])
200 if remote_servers:
201 print(f"\n[✓] Found {len(remote_servers)} remote MCP server(s) in config:")
202 for server in remote_servers:
203 print(f" - {server['id']}: {server['url']}")
204 await init_mcp_tools(remote_servers=remote_servers)
205 else:
206 print("\n[✗] No remote MCP servers configured")
207
208 # Get registry statistics
209 registry = get_registry()
210 print("\n" + "="*60)
211 print("TOOL REGISTRY STATISTICS")
212 print("="*60)
213 print(f"Total tools loaded: {registry.total_tool_count()}")
214 print(f" - Function tools: {len(registry)}")
215 print(f" - MCP tools: {registry.total_tool_count() - len(registry)}")
216 print(f"\nRegistered tool names:")
217 for name in sorted(registry.get_all_names()):
218 print(f" - {name}")
219
220 # Step 2: Initialize model
221 print("\n" + "="*60)
222 print("MODEL & AGENT INITIALIZATION")
223 print("="*60)
224 print("\nInitializing model...")
225 model = OpenAIModel(
226 api_key=os.getenv("OPENAI_API_KEY"),
227 model_name="gpt-4o",
228 temperature=0.7

Callers 1

mcp_demo.pyFile · 0.70

Calls 12

get_registered_toolsMethod · 0.95
executeMethod · 0.95
init_toolsFunction · 0.90
init_mcp_toolsFunction · 0.90
get_registryFunction · 0.90
OpenAIModelClass · 0.90
cleanup_mcpFunction · 0.90
total_tool_countMethod · 0.80
get_all_namesMethod · 0.80
MyAgentClass · 0.70
getMethod · 0.45
getenvMethod · 0.45

Tested by

no test coverage detected