Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:
- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Onshape MCP: How AI can ask 30 questions for the price of 1 API call
The problem:
I assumed my production pipeline was the expensive part. It is not. A real customer-facing order costs 9 API requests, and I have that measured across ten of them.
One afternoon of me poking at a model through an MCP server cost 21. That is more than two customer orders, for an afternoon of asking questions. An earlier debugging session cost about 70.
The reason is not complicated. Every time you ask an MCP-style tool a question, it asks Onshape several questions of its own to work out where to look, and then asks yours. In my case roughly three and a half requests went out for every one I thought I was making. Nothing is broken. It is just chatty, on your allowance, invisibly.
The fix:
The FeatureScript evaluation endpoint takes a function and runs it inside your model. Almost everyone sends it one question at a time. How many faces, one request. Bounding box, another request. Volume, another.
You do not have to. A function can hand back a whole list of answers, so you can ask everything at once and pay for one request. Here is the entire idea:
function(context is Context, queries is map){ var out = {}; out["faces"] = size(evaluateQuery(context, qEverything(EntityType.FACE))); out["bbox"] = evBox3d(context, { "topology" : qEverything(EntityType.BODY) }); return out;}
Add another twenty lines to that and it is still one request. I have run thirteen answers out of a single call.
The catch, which is the whole reason I wrote this
If one of your questions is bad, you get nothing back. Not the other twenty-nine answers and one error. Nothing, including answers that had already been worked out.
You can protect each question individually so a bad one only costs itself, and you should. But then the failed answer does not come back as an error either. It simply is not in the reply. Which looks exactly like a question you forgot to ask.
That is the part that turns a saving into a wrong answer you then trust, and it is why I would not recommend doing this by hand without reading the notes first.
Two smaller ones while I am here. The function signature you will find all over this forum produces a warning from Onshape and should have a map as its second argument, not an Id. And measurements come back converted to metres and radians, so 25 mm arrives as 0.025.
For Onshape, if you are reading
Two requests, and they are really the same one.
Send back partial results. The all-or-nothing reply is the only reason batching is risky, and that risk is why everyone keeps making one call per question. Return what succeeded plus a list of what did not, and batching becomes the obvious default instead of an advanced trick with a trap in it. That would cut API load across your whole integrator base, which I recognise is an odd thing to be asking for.
Do not silently drop the failed ones. Return the key with an error marker rather than omitting it. Everything else here is convenience. This one is the difference between an obvious failure and a quietly incomplete answer.
Underneath both: the response format is not documented anywhere, so all of us reverse-engineer it separately and each get a different part of it right.
Credit where it is owed. X-Rate-Limit-Remaining coming back on every response is genuinely useful and I wish more APIs bothered. And the translation-complete webhook exists, which saved me from building something silly with a polling loop.
Code and full notes
A small client that handles all the traps, a tool that reports any Part Studio in one request, and everything I measured with the version numbers attached:
https://github.com/arthob/onshape-batch-eval
MIT, not selling anything. If your results differ from mine I would like to know, ideally with the library version you saw.
Categories
- All Categories
- 10.2K Community Support
- 4.6K General
- 194 Account and subscriptions
- 353 Data management
- 1.6K Product Feedback
- 215 New in Onshape
- 14 Onshape Labs
- 75 CAM Studio
- 35 PCB Studio
- 107 Simulation
- 209 Onshape Mobile
- 315 App Store & Partners Apps
- 8.2K Using Onshape
- 1.8K Drawings
- 2.3K FeatureScript
- 324 Learning Center
- 253 Education Community