Skip to content

MCP Server

Manvendra Bhardwaj edited this page May 23, 2026 · 1 revision

MCP Server

What is MCP?

Model Context Protocol (MCP) is a standard that lets AI models call external tools in a structured way. Instead of the AI guessing at a solution, MCP lets it take real actions — read files, run commands, search code — and receive real results back before deciding the next step.

Transport

The MCP Server uses SSE (Server-Sent Events) as its transport layer.

  • GET /sse — The Backend connects here when it starts up. This establishes a persistent session.
  • POST /messages?sessionId=... — Tool calls from the AI are sent here during the agent loop.

When the backend boots, it immediately connects to the MCP Server via /sse and holds that connection open. Every tool call during an agent loop goes through this session.

Tools

listFiles

Lists all files and folders inside a given directory. The AI uses this first to understand the structure of the uploaded project.

Input: directorypath — path to the project directory.

readFile

Reads the full content of a single file. The AI uses this after identifying which files are relevant.

Input: filepath — absolute path to the file.

searchCodebase

Searches for a keyword or phrase across all files in the project. Useful for tracing where a variable, function, or error message is used.

Input: directoryPath — project root. keyword — the string to search for.

runCommand

Executes a terminal command inside the project directory. The AI uses this to install dependencies, start the project, or reproduce the error.

Input: command — the command string. workingDirectory — where to run it.

analyzeLogs

Takes raw runtime logs or error output and returns an analysis of what went wrong and why.

Input: logs — the error or log string.

writeFile

Writes or overwrites a file with new content. The AI uses this to apply fixes after identifying the root cause.

Input: filepath — file to write. content — new file content.

Agent Loop Workflow

The agent follows this general sequence, though it adapts based on what it finds:

  1. Call listFiles to understand the project structure.
  2. Call searchCodebase to find relevant code related to the bug.
  3. Call readFile on files that look important.
  4. Call runCommand to reproduce the error or check runtime behavior.
  5. Call analyzeLogs on the output.
  6. Call writeFile to apply a fix if needed.
  7. Return a final explanation to the user.

The loop runs for a maximum of 20 tool calls. If the limit is reached, the agent returns whatever conclusion it has reached so far.

Tool Timeout

Each tool call has a timeout (10–15 seconds depending on the tool). If a tool does not respond in time, the agent receives a timeout message and continues to the next step. This prevents the loop from hanging on slow commands like npm install.

Clone this wiki locally