Skip to content

feat(mcp) #4867: add configurable tool profiles - #5402

Merged
robfrank merged 3 commits into
ArcadeData:mainfrom
justinblethrow-cloud:feature/mcp-tool-profiles
Jul 27, 2026
Merged

robfrank merged 3 commits into
ArcadeData:mainfrom
justinblethrow-cloud:feature/mcp-tool-profiles

Conversation

@justinblethrow-cloud

Copy link
Copy Markdown
Contributor

Summary

  • add persisted all, rag, and admin Model Context Protocol (MCP) tool profiles
  • filter tools/list through the active profile
  • enforce the same allowlist in tools/call so hidden tools cannot be invoked directly
  • provide retrieval-focused initialization instructions for the rag profile
  • document profile contents, configuration, and permission boundaries

Behavior

profile defaults to all, preserving the current tool surface exactly.

The rag profile permits registered retrieval tools:

  • query
  • full_text_search
  • sample_records
  • vector_search
  • hybrid_search

Only tools registered by the running server are advertised. This lets pending retrieval tools join the existing profile allowlist when installed without advertising unavailable tools.

The admin profile exposes the original operator and database-administration surface. Schema Resources remain available through the MCP Resources capability rather than consuming a tool slot.

Profiles restrict tool visibility and invocation; they do not grant read, write, schema, administrative, user, or origin permissions. Those existing checks remain mandatory.

Unknown profile values return HTTP 400 from the configuration endpoint and are rejected before any other field in the same update is applied.

Validation

  • focused profile, configuration, HTTP, and standard input/output tests: 109 passed
  • complete MCP-only server test set: 146 passed
  • final mixed-case configuration regression test: 12 passed
  • no failures or skipped tests

Closes #4867

@mergify

mergify Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codacy-production

codacy-production Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@robfrank robfrank added this to the 26.8.1 milestone Jul 24, 2026
@robfrank robfrank added the mcp Model Context Protocol server label Jul 24, 2026
@codecov

codecov Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.34%. Comparing base (3226999) to head (15cabb3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...java/com/arcadedb/server/mcp/MCPConfiguration.java 79.41% 5 Missing and 2 partials ⚠️
...in/java/com/arcadedb/server/mcp/MCPDispatcher.java 96.15% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5402      +/-   ##
============================================
- Coverage     65.38%   65.34%   -0.05%     
- Complexity     1001     1103     +102     
============================================
  Files          1733     1734       +1     
  Lines        144421   144560     +139     
  Branches      30959    30980      +21     
============================================
+ Hits          94436    94459      +23     
- Misses        36881    37261     +380     
+ Partials      13104    12840     -264     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@robfrank

Copy link
Copy Markdown
Collaborator

Reviewed against the epic #4859 acceptance criteria. The mechanics here are right: the profile is an allowlist enforced at both tools/list and tools/call, so a client cannot invoke a hidden tool by name; an unknown profile value is rejected before any other field in the same update is applied; and forward-declaring vector_search, hybrid_search and sample_records in RAG_TOOL_NAMES while gating everything through REGISTERED_TOOL_NAMES is a genuinely nice way to decouple this from the merge order of the Wave 1 tools. The MCPConfigHandler change from a 500 to a 400 on bad input is a real improvement.

The problems are with the profile contents and the scope of the setting, not the implementation.

1. The rag profile has no schema discovery (blocking)

RAG_INSTRUCTIONS tells the agent:

Read the arcadedb://{database}/schema Resource before searching an unfamiliar database.

But RAG_TOOL_NAMES excludes both get_schema and list_databases. MCP Resources support is still uneven across clients, and plenty of them expose Tools only. On such a client a rag-profile agent cannot discover type names, property names, or even which databases exist. It is left to guess identifiers and feed them to query, which is exactly the failure #4859 wants the retrieval surface to prevent.

Right now the effective rag profile on main is two tools, query and full_text_search, which is a smaller surface than is usable. Please add get_schema, and list_databases unless you have a specific reason to withhold it.

2. No profile exposes the agent-memory write tools

upsert_entity and upsert_relationship appear in neither rag nor admin, so they are reachable only under all.

#4859 is titled "GraphRAG and Agent-Memory Surface", and #4864 shipped those two tools specifically for the knowledge-graph-construction persona. As it stands, any operator who selects a profile to narrow the surface loses agent-memory writes entirely, and the only way to keep them is to select all and give up the narrowing that is the whole point of the feature.

Either add a memory (or kg) profile pairing the upserts with the retrieval tools, or include them in rag on the grounds that agent memory both reads and writes. My preference is the latter, since a separate profile per persona multiplies quickly. Whichever you choose, the profile permission is orthogonal to the write flags, which stay false by default, so this does not weaken the safe-by-default posture.

3. The profile is server-global, but the criterion is per agent

#4859's success criterion is "The tool surface a given agent sees stays small via configurable profiles." A single server-wide profile field cannot give the retrieval agent rag and the DBA all at the same time. Serving both personas means running two servers, which defeats the purpose.

#5401 is concurrently introducing per-database permission scoping keyed on the authenticated principal, and already has the resolver plumbing for exactly this. Profiles should key off the same principal. I am not asking you to build that in this PR, but please note it in the spec's out-of-scope section (which currently justifies the global choice on the grounds that "the current endpoint advertises one tool surface", which is circular) and open a follow-up. Otherwise the criterion reads as satisfied when it is not.

4. Smaller points

MCPConfigHandler now maps IllegalArgumentException to 400, but the rest of updateFrom still throws JSONException on a type mismatch such as {"enabled": "yes"}, which surfaces as a 500. Worth widening the catch while you are in there.

toolsForProfile returns the shared static TOOLS_LIST instance for ALL and a freshly built array otherwise. The aliasing predates this PR, but the method now has two different ownership semantics depending on the branch. Return a copy in both.

Cross-PR: the test assertions will break each other

toolProfilesFilterDiscoveryAndExecution asserts the rag profile is exactly {"query", "full_text_search"} in both MCPServerPluginTest and MCPStdioServerTest. That breaks the moment #5398 (sample_records) or #5399 (vector_search) registers, since both names are already in RAG_TOOL_NAMES.

The mirror image is also true: #5398 and #5399 each change assertThat(tools.length()).isEqualTo(13) to isEqualTo(14), so whichever of those merges second is red as well.

Across all four PRs, please derive the expected names and count from the registered tool list rather than hardcoding, or assert containment only. That is the one change that removes the merge-order coupling entirely.

Cross-PR: conflict with #5401

#5401 modifies MCPConfiguration.load(), updateFrom() and toJSON() in the same hunks this PR does, and both add assertThatThrownBy plus assertions to MCPConfigurationTest.saveAndLoad and toJSON. Both use the same "parse and validate before mutating" pattern, so the merge is mechanical, but whoever goes second should re-run MCPConfigurationTest rather than trusting the resolution.

@justinblethrow-cloud

Copy link
Copy Markdown
Contributor Author

Thanks, Roberto. Addressed in f4e250b3:

  • rag now includes list_databases, get_schema, upsert_entity, and upsert_relationship, while the existing write flags remain independent and denied by default.
  • Initialization guidance now covers tools-only schema discovery and agent-memory writes.
  • Invalid boolean configuration types are rejected and returned as HTTP 400.
  • toolsForProfile returns a fresh array for every profile.
  • Exact profile/tool-count assertions were replaced with containment and behavior assertions.
  • The server-global limitation is explicit in the design note. The requested per-principal follow-up is open as MCP: support per-principal tool profiles on a shared endpoint #5445.

Focused validation: MCPConfigurationTest, MCPPermissionsTest, MCPServerPluginTest, and MCPStdioServerTest; 113 tests passed.

@robfrank

Copy link
Copy Markdown
Collaborator

Correction to my review above: I did not raise the docs criterion from #4859 because I had wrongly concluded no MCP documentation lives in this repo. The MCP reference page is at https://docs.arcadedb.com/arcadedb/reference/mcp/mcp and its source is ArcadeData/arcadedb-docs, file src/main/asciidoc/reference/mcp/mcp.adoc.

That page documents the mcp-config.json keys as exactly enabled, allowReads, allowInsert, allowUpdate, allowDelete, allowSchemaChange, allowAdmin, allowedUsers, allowedOrigins. This PR adds profile, and it is the key an operator most needs to find, because it is the one that changes which tools an agent can see at all.

Please open a companion arcadedb-docs PR documenting profile: the three accepted values, the exact tool membership of rag and admin once points 1 and 2 of my review are settled, the fact that it is an allowlist enforced at both discovery and invocation, and the fact that it never grants an operation, since the read/write flags remain independent mandatory checks. That last point is the one most likely to be misread as a permission mechanism.

One thing that makes point 1 of my review sharper: the page does not mention MCP Resources anywhere, so the arcadedb://{database}/schema resource from #4865 is shipped but undocumented. RAG_INSTRUCTIONS directs the agent to a facility that is both unevenly supported across clients and absent from the documentation, while get_schema is excluded from the profile. Documenting the resource is not this PR's debt and I will file it separately, but it reinforces that rag should carry get_schema.

@justinblethrow-cloud

Copy link
Copy Markdown
Contributor Author

Companion documentation is now open as ArcadeData/arcadedb-docs#428.

It documents the three profile values, exact rag and admin memberships, version-dependent registration, enforcement at both discovery and invocation, independent mandatory permission checks, and the current server-global scope.

Validation on the standalone documentation branch:

  • python3 docs-validator.py
  • ./mvnw generate-resources

@justinblethrow-cloud
justinblethrow-cloud force-pushed the feature/mcp-tool-profiles branch from f4e250b to 23a7cb0 Compare July 27, 2026 08:44
Resolves the overlap with sample_records (ArcadeData#5398) and vector_search (ArcadeData#5399), both now
on main. The conflict was confined to the stdio discovery test, which each side had
independently rewritten off the old hardcoded tool count.

Keeps this branch's version, which asserts through the toolNames helper, and folds
sample_records into it.

Now that both Wave 1 tools have landed, the profile membership assertions cover them:
the rag profile is asserted to expose sample_records and vector_search, and the admin
profile is asserted not to. That is the check ArcadeData#4859 sequenced this PR to make once the
Wave 1 tool names settled.

Also imports JSONException in MCPConfigurationTest rather than naming it inline, per
the project convention against fully qualified names.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@robfrank

Copy link
Copy Markdown
Collaborator

Both Wave 1 tools are now on main (vector_search #5399, sample_records #5398), which is the point #4859 sequenced this PR for: the rag profile membership can finally be settled against real tool names. I have merged main in and pushed, so this is mergeable again.

On your fix commit

23a7cb0d4 resolves the substantive findings, and the choices are the right ones:

  • rag now carries list_databases and get_schema, so a retrieval agent on a Tools-only client can actually discover what it is searching. This was my blocking point.
  • rag now carries upsert_entity and upsert_relationship, so the agent-memory half of the epic survives profile selection. Folding them into rag rather than minting a separate profile is the choice I would have made.
  • RAG_INSTRUCTIONS was rewritten to match the new membership instead of pointing only at the Resources API.
  • MCPConfigHandler now catches JSONException alongside IllegalArgumentException, and MCPConfiguration raises a typed error naming the offending field, so {"enabled": "yes"} is a 400 with a usable message rather than a 500.
  • toolsForProfile always builds a fresh array, and toolsListReturnsIndependentArrays pins it. That closes the shared-TOOLS_LIST aliasing.

I checked for the pattern that bit the vector_search truncation fix, where new reporting quietly introduced an O(n) scan. Nothing comparable here: profile resolution is a Set lookup against a Set.copyOf built once in the static initializer.

What I changed on top

The only conflict was the stdio discovery test, which this branch and main had each rewritten off the old hardcoded count. I kept this branch's version, which goes through the toolNames helper, and folded sample_records into it.

Then I extended the profile assertions, since the Wave 1 names have settled and the tests were written before they existed. Both the HTTP and stdio profile tests now assert rag exposes sample_records and vector_search, and admin does not. Without that, RAG_TOOL_NAMES could list a tool that never actually reaches a client and nothing would catch it, which is precisely the gap the forward-declaration plus REGISTERED_TOOL_NAMES design creates.

I also imported JSONException in MCPConfigurationTest rather than naming it inline, per the project convention against fully qualified names.

mvn test -Dtest='MCPServerPluginTest,MCPStdioServerTest,MCPConfigurationTest,MCPPermissionsTest' is green at 133 tests.

Still open

Profiles are server-global. This is the one review point not addressed, and I do not think it should block the PR. #4859's criterion is that the surface a given agent sees stays small, and a single server-wide profile cannot serve a retrieval agent and a DBA from one endpoint. #5401 is introducing per-database resolution keyed on the authenticated principal, which is the natural place for this to key off too. Please either note it in the spec's out-of-scope section with that reasoning, or open a follow-up issue so the criterion is not recorded as met when it is partly met. Right now the spec justifies the global choice on the grounds that the endpoint advertises one tool surface, which is circular.

Docs. The arcadedb-docs gap has grown to three items: profile is a new top-level mcp-config.json key, and the page still predates both Wave 1 tools. One PR covering profile, sample_records and vector_search would close it. The profile entry matters most, because it is the setting that changes which tools an agent can see at all, and it must be clear that a profile never grants an operation since the read and write flags remain independent mandatory checks.

@justinblethrow-cloud

Copy link
Copy Markdown
Contributor Author

Thanks, Roberto. I reviewed the merge resolution and agree with the settled Wave 1 profile assertions.\n\nThe two remaining items are already covered:\n\n- The design spec's Out of scope section explicitly states that the server-global profile cannot present different surfaces to different agents, says that this only partly satisfies #4859, and links the per-principal follow-up #5445.\n- The documentation is split into the already-open companion PRs ArcadeData/arcadedb-docs#425 (sample_records), ArcadeData/arcadedb-docs#426 (vector_search), and ArcadeData/arcadedb-docs#428 (profile). All three passed docs-validator.py and ./mvnw generate-resources.\n\nNo additional code change appears necessary from these two points.

@robfrank robfrank changed the title feat(mcp): add configurable tool profiles feat(mcp) #4867: add configurable tool profiles Jul 27, 2026
@robfrank
robfrank merged commit 68d6596 into ArcadeData:main Jul 27, 2026
14 of 20 checks passed
robfrank added a commit to justinblethrow-cloud/arcadedb that referenced this pull request Jul 27, 2026
Resolves the overlap with tool profiles (ArcadeData#5402), which landed on main and added its
own field, load, updateFrom and toJSON handling to MCPConfiguration alongside the
per-database overrides added here.

Both features are kept everywhere they collided. Where the two sides differed on how
allowAdmin is read, main's strict booleanValue() wins, so a non-boolean value is still
rejected with a typed error rather than coerced.

Also refreshes the spec's enforcement list, which had gone stale: it named six
database-targeted tools while the code now scopes eight, since sample_records (ArcadeData#5398)
and vector_search (ArcadeData#5399) were wired to the resolver after the spec was written. The
list is normative for the "future tools must use the same resolver" rule, so it now
records the required access each tool declares and why the write tools ask for ACCESS.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
robfrank added a commit that referenced this pull request Aug 14, 2026
Co-authored-by: robfrank <ro.franchini@gmail.com>
(cherry picked from commit 68d6596)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mcp Model Context Protocol server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: tool profiles in MCPConfiguration

2 participants