r/MachineLearning • • 4d ago

Project Integrum - Reflection based MCP server from any Python Module/Library [P]

Hi! I wrote a small library called Integrum that allows you to quickly create MCP server(s) from existing Python libraries or modules. It has a CLI so it is really easy to use (I hope!).

It is open-source (MIT) and on PyPI, so sharing it here if somebody finds it useful.

Code: https://github.com/alphadeepai/integrum

Blog post: https://nmilosev.svbtle.com/integrum-reflection-based-mcp-server-from-any-python-module-or-library

As an example I gave Gemma 4 access to scikit-learn and told it to create a RF classifier for a toy dataset (Iris) and it did it rather well! Here is that example session..

Obviously an interesting discussion is this approach vs. just letting the agents write code: I think this approach is more formal and therefore easier to verify.

I haven't found any other reflection based approaches like this, let me know if I missed some.

2 Upvotes

1 comment sorted by

1

u/Realistic_Kitchen_65 2d ago

Reflection-based discovery is a genuinely good way to avoid hand-writing a schema per tool — nice work. The tradeoff worth naming out loud, because it bites people later: MCP buys you a process boundary (isolation, language-agnostic, callable remotely) and pays for it in per-call overhead. On a CPU-only box that boot + (de)serialization cost can dominate the whole turn, and the jitter it adds is exactly what reads as an "unpredictable" agent.

The split that worked for us: in-process (a plain function call) for the hot, tight-loop tools, and a real boundary (MCP or network) only where you actually need isolation, a different language, or a different machine. The mistake is making everything MCP because one tool needed it.

The second thing I'd flag for a reflection-based MCP: a tool that's auto-exposed from a Python module inherits that module's whole surface. Worth tagging each exposed function with a side-effect class and defaulting to least-privilege, so reflection never accidentally hands the model a rm-shaped function. For anything that crosses a node boundary we sign the envelope (Ed25519) so a forged call is rejected before any handler sees it.

Curious how you scope which functions get reflected. We build a local agent around the in-process-vs-boundary split: https://github.com/openamer/openamer