selfmcp: The MCP Server That Lets an AI Write Its Own Tools

A tiny Python kernel, a versioned skill registry, and a subprocess executor turn a model into a system that can extend itself in real time.

8 min read • View on GitHub • More from yoheinakajima

A wide editorial scene of a compact workbench with eight switches on one side and a mechanical hand drafting a new tool blueprint on the other. The blueprint feeds back into the bench while a stack of indexed cards grows behind it, showing how the system can create and store its own capabilities.
selfmcp treats tool creation as part of the loop, not a one-time setup step. The agent can draft a new skill, store it, and use it again later.

The current BabyAGI is a self-building framework—an agent that can write its own functions.

Yohei Nakajima, General Partner, Untapped Capital & Creator of BabyAGI · Yohei Nakajima's Build-in-Public AI Agent System | self.md
Key Takeaways

The AI Is Not Just Using Tools. It Is Making Them

Most MCP servers expose a fixed menu of actions. selfmcp flips that script. It gives the model a small kernel of tools, then lets it write new Python skills, save them, search them later, and execute them inside the same session.

A hedcut-style portrait of Yohei Nakajima rendered in black ink on white. The likeness is used to identify the project creator and connect the article to his public writing about self-building agents.

Eight Tools, Not Eighty

The point is not a giant API surface. The point is a small set of tools that can generate more tools without redeploying the server.

Project typeTool sourceHow new capability appearsSearch/discovery modelRisk profile
Standard MCP serverFixed external integrationsA new server or connector must be added by a humanList and call predefined endpointsLower flexibility, lower code execution risk
Conventional agent frameworkPredefined tools plus orchestrationCapability is usually scripted ahead of timePlanner picks from a known tool listModerate flexibility, higher orchestration complexity
selfmcpDynamic skill registryThe model writes, stores, and reuses its own Python skillsLightweight summary first, full code on demandHighest flexibility, highest safety burden

Skills as Data

The elegant idea in skills.py and db.py is that a skill is not a magical runtime object. It is a row in a registry with a name, description, and code body. The server first shows a narrow table of contents, then reveals full code only when a specific skill is worth opening.

A close-up of a registry drawer with three layers visible. The top layer shows a tiny table of contents, the middle layer opens a full code file, and the bottom layer preserves an older version with a timestamp label. A search lens points to the exact skill card being selected, explaining how discovery and versioning work together.
This is a materialized table of contents. The model gets a short list first, then expands only the entry it needs, while older versions remain attached to the record.
PatternWhat the LLM sees firstWhat happens nextWhy it matters
Materialized TOCA short skill summary listFetch detail only for the chosen skillKeeps context lean
Full dumpEverything at onceThe model sorts through too much textWastes context and attention
Append-only historyCurrent skill plus prior versionsOlder bodies stay recoverableSupports rollback and auditability

How a Skill Becomes an Executable

The runtime is deliberately simple. `executor.py` writes generated code to a tempfile, passes parameters through `SELFMCP_PARAMS`, and launches a subprocess. That makes a skill easy to inspect, portable across environments, and close to the way a human would actually ship a small script.

def execute_skill(code: str, params: dict[str, object]) -> str:
    with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
        f.write(extract_code_block(code))
        path = f.name

    env = os.environ.copy()
    env["SELFMCP_PARAMS"] = json.dumps(params)

    result = subprocess.run(
        [sys.executable, path],
        capture_output=True,
        text=True,
        env=env,
        check=False,
    )
    return result.stdout

The important part is not that code runs. It is that the generated code stays human-readable, can be archived as Markdown, and can be re-opened as a versioned artifact instead of a throwaway string.

Search Keeps the Growing Library Usable

Once the library starts to grow, retrieval stops being optional. `embeddings.py` adds hybrid search so the model can find likely matches without scanning the entire registry, and the deterministic local fallback means the system still works when an embedding API is unavailable.

Search modeStrengthWeaknessBest use
Semantic searchFinds related skills by meaningDepends on embeddings qualityGrowing libraries with fuzzy queries
Local fallbackAlways available and deterministicLess semantically richOffline or API-free environments
Naive list scanSimple and transparentDoes not scale wellTiny skill sets only

The Trade-Off Is the Point

This project does not pretend to be a hardened sandbox. Skills inherit the server environment, deleted names can be reactivated, and subprocess execution keeps the system flexible at the cost of stronger isolation. That is the central tension: self-extension is useful precisely because it is permissive.

Tools like`FastAPI-MCP` are gaining traction because they simplify turning existing services into MCP-compatible ones with zero configuration.

Yohei Nakajima, General Partner, Untapped Capital & Creator of BabyAGI · 🔍 Key Trends & Insights on MCP Clients – Yohei Nakajima
Questionselfmcp answerSafer alternative
Who owns tool creation?The model doesA human developer does
Are tools fixed?No, they grow during the sessionYes, the API surface is static
Is history preserved?Yes, through versioningOften only the latest state exists
Is the runtime tightly sandboxed?Not by designUsually yes

Why This Matters in the MCP Era

The larger landscape makes the contrast sharper. Standard MCP servers connect models to existing tools. Agent frameworks orchestrate those tools. selfmcp does something else entirely. It treats the model as a producer of tools, not just a consumer of them, which turns MCP into a self-extension layer instead of a mere connector standard.

What selfmcp Suggests About Agents

This repo is less a polished product than a design sketch for recursive software. Its real argument is that agent progress may come not only from bigger context windows or better prompts, but from systems that let models grow their own working set over time.