This repository contains a local AI agent built for civil engineering applications. It uses a local model to evaluate structural safety via a Model Context Protocol (MCP) server.
The system consists of a Python-based MCP server exposing physics calculation tools, and an agent script that uses openai to connect a local Ollama model to the server via standard input/output (stdio).
The MCP server (server.py) exposes three distinct tools:
get_material_properties: Fetches Young's Modulus and Yield Strength.calculate_beam_deflection: Computes physical deflection based on load and beam geometry.check_safety_factor: Evaluates stress ratios against standard safety limits.
The agent independently determines the correct sequence of tools based on the user's natural language prompt. For example, querying a load on a steel beam triggers the agent to sequence the deflection tool followed by the safety factor tool.
The MCP tools use standard try-except blocks. If an invalid material is requested or a mathematical operation fails, the tools return explicit string error messages (e.g., "Calculation failed: [reason]"). This allows the agent to read the error context and react appropriately rather than crashing the execution pipeline.
The agent connects to the local Ollama instance using the AsyncOpenAI client pointing to http://localhost:11434/v1. To swap the local model for a stronger OpenAI-compatible API during final evaluation, you only need to change the base_url, api_key, and model parameters in agent.py. No other agent architecture changes are required.
- Run
ollama run qwen2.5to start the local model. - Install requirements:
pip install mcp<2 openai - Execute the agent:
python agent.py