Skip to content

Improved MCP server with init instructions and server list in query error#3896

Closed
ExtReMLapin wants to merge 3 commits into
ArcadeData:mainfrom
ExtReMLapin:improved_mcp
Closed

Improved MCP server with init instructions and server list in query error#3896
ExtReMLapin wants to merge 3 commits into
ArcadeData:mainfrom
ExtReMLapin:improved_mcp

Conversation

@ExtReMLapin

Copy link
Copy Markdown
Contributor

I was running tests with Qwen code, and it was tasked to run cypher queries on both neo4j and arcadedb.

Goofy qwen didn't bother getting the list of the databases first.

Now, it has instructions to do it first, and even if it fails to do so and go for an non existing base it will get the list of the bases in the error

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the MCP implementation by adding specific instructions for LLMs and introducing a MCPToolUtils.resolveDatabase utility to provide a list of authorized databases when a requested database is not found. Feedback suggests improving the database filtering logic in the utility for better robustness and centralizing the security authorization check. Currently, manual security checks in the tool classes are performed before the resolution logic, which prevents restricted users from receiving the helpful list of available databases when a typo occurs.

Comment on lines +41 to +44
final Set<String> installed = new TreeSet<>(server.getDatabaseNames());
final Set<String> allowed = user.getAuthorizedDatabases();
if (!allowed.contains("*"))
installed.retainAll(allowed);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using user.canAccessToDatabase(db) to filter the list is more robust than manually checking for * and using retainAll. This approach correctly leverages the existing security logic in the ServerSecurityUser class, which may include complex rules or wildcards beyond a simple * check.

Suggested change
final Set<String> installed = new TreeSet<>(server.getDatabaseNames());
final Set<String> allowed = user.getAuthorizedDatabases();
if (!allowed.contains("*"))
installed.retainAll(allowed);
final Set<String> installed = new TreeSet<>(server.getDatabaseNames());
installed.removeIf(db -> !user.canAccessToDatabase(db));

"Database '" + databaseName + "' does not exist. Available databases: " + installed
+ ". Use one of these names or call list_databases to refresh the list.");
}
return server.getDatabase(databaseName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider centralizing the database authorization check here. By moving the canAccessToDatabase check into this utility method, you ensure that all tools using resolveDatabase are consistently protected. Furthermore, this allows the 'Available databases' error message to be reached even when a restricted user makes a typo, which is currently blocked by the manual checks in the tool classes.

    if (!user.canAccessToDatabase(databaseName))
      throw new SecurityException("User '" + user.getName() + "' is not authorized to access database '" + databaseName + "'");
    return server.getDatabase(databaseName);

throw new SecurityException("User '" + user.getName() + "' is not authorized to access database '" + databaseName + "'");

final Database database = server.getDatabase(databaseName);
final Database database = MCPToolUtils.resolveDatabase(server, user, databaseName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The security check on lines 76-77 (context) is currently executed before resolveDatabase. For restricted users, this means a typo in the database name will trigger a SecurityException instead of the helpful error message containing the list of available databases. Consider moving the authorization check inside resolveDatabase or after it to ensure the 'Available databases' feature works for all users.

throw new SecurityException("User '" + user.getName() + "' is not authorized to access database '" + databaseName + "'");

final Database database = server.getDatabase(databaseName);
final Database database = MCPToolUtils.resolveDatabase(server, user, databaseName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The manual security check on lines 75-76 (context) prevents restricted users from seeing the list of available databases when they provide an incorrect database name. If the authorization check is moved inside or after resolveDatabase, the LLM will be able to self-correct using the provided list.

throw new SecurityException("User '" + user.getName() + "' is not authorized to access database '" + databaseName + "'");

final Database database = server.getDatabase(databaseName);
final Database database = MCPToolUtils.resolveDatabase(server, user, databaseName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to other tools, the preceding security check (lines 60-61) blocks the helpful error message for restricted users. Centralizing this check within resolveDatabase would improve the user experience and maintainability.

@codacy-production

codacy-production Bot commented Apr 19, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity

Metric Results
Complexity 4

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. Give us feedback

@robfrank

Copy link
Copy Markdown
Collaborator

@ExtReMLapin can you rebase and push again? thanks

@ExtReMLapin

Copy link
Copy Markdown
Contributor Author

Done !

@codecov

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.78%. Comparing base (4cb5061) to head (ac9f0e8).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
...va/com/arcadedb/server/mcp/tools/MCPToolUtils.java 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3896      +/-   ##
==========================================
- Coverage   64.46%   63.78%   -0.69%     
==========================================
  Files        1587     1588       +1     
  Lines      118612   118620       +8     
  Branches    25194    25195       +1     
==========================================
- Hits        76468    75659     -809     
- Misses      31548    32483     +935     
+ Partials    10596    10478     -118     

☔ View full report in Codecov by Sentry.
📢 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

supersede by #3966

Thank you for your contribution!

@robfrank robfrank closed this Apr 23, 2026
tae898 pushed a commit to humemai/arcadedb-embedded-python that referenced this pull request Jun 28, 2026
…io [skip ci]

Bumps [marked](https://github.com/markedjs/marked) from 15.0.12 to 17.0.4.
Release notes

*Sourced from [marked's releases](https://github.com/markedjs/marked/releases).*

> v17.0.4
> -------
>
> [17.0.4](markedjs/marked@v17.0.3...v17.0.4) (2026-03-04)
> -----------------------------------------------------------------------------------
>
> ### Bug Fixes
>
> * prevent ReDoS in inline link regex title group ([ArcadeData#3902](https://redirect.github.com/markedjs/marked/issues/3902)) ([46fb9b8](markedjs/marked@46fb9b8))
>
> v17.0.3
> -------
>
> [17.0.3](markedjs/marked@v17.0.2...v17.0.3) (2026-02-17)
> -----------------------------------------------------------------------------------
>
> ### Bug Fixes
>
> * escape image alt text ([ArcadeData#3896](https://redirect.github.com/markedjs/marked/issues/3896)) ([909fe44](markedjs/marked@909fe44))
>
> v17.0.2
> -------
>
> [17.0.2](markedjs/marked@v17.0.1...v17.0.2) (2026-02-11)
> -----------------------------------------------------------------------------------
>
> ### Bug Fixes
>
> * fix blockquote after list ([ArcadeData#3888](https://redirect.github.com/markedjs/marked/issues/3888)) ([2a475a1](markedjs/marked@2a475a1))
> * fix empty list item ([ArcadeData#3890](https://redirect.github.com/markedjs/marked/issues/3890)) ([3fc6a44](markedjs/marked@3fc6a44))
> * fix list item wrong indent ([ArcadeData#3889](https://redirect.github.com/markedjs/marked/issues/3889)) ([e031175](markedjs/marked@e031175))
> * fix list with tabs ([ArcadeData#3891](https://redirect.github.com/markedjs/marked/issues/3891)) ([9fc4f8e](markedjs/marked@9fc4f8e))
> * fix strikethrough flanking rules ([ArcadeData#3882](https://redirect.github.com/markedjs/marked/issues/3882)) ([1a5b124](markedjs/marked@1a5b124))
>
> v17.0.1
> -------
>
> [17.0.1](markedjs/marked@v17.0.0...v17.0.1) (2025-11-20)
> -----------------------------------------------------------------------------------
>
> ### Bug Fixes
>
> * fix block elements in task item ([ArcadeData#3828](https://redirect.github.com/markedjs/marked/issues/3828)) ([921ee22](markedjs/marked@921ee22))
>
> v17.0.0
> -------
>
> [17.0.0](markedjs/marked@v16.4.2...v17.0.0) (2025-11-07)
> ===================================================================================
>
> ### Bug Fixes
>
> * only create tokens inside tokenizers ([ArcadeData#3755](https://redirect.github.com/markedjs/marked/issues/3755)) ([7b19231](markedjs/marked@7b19231))
>
> ### BREAKING CHANGES
>
> * Change how consecutive text tokens work in lists
> * Simplify listItem renderer
> * Checkbox token is added in list tokenizer

... (truncated)


Commits

* [`22f0c55`](markedjs/marked@22f0c55) chore(release): 17.0.4 [skip ci]
* [`46fb9b8`](markedjs/marked@46fb9b8) fix: prevent ReDoS in inline link regex title group ([ArcadeData#3902](https://redirect.github.com/markedjs/marked/issues/3902))
* [`5b6faee`](markedjs/marked@5b6faee) chore(deps-dev): Bump eslint from 10.0.1 to 10.0.2 ([ArcadeData#3904](https://redirect.github.com/markedjs/marked/issues/3904))
* [`bcdaf6a`](markedjs/marked@bcdaf6a) chore(deps-dev): Bump `@​semantic-release/npm` from 13.1.4 to 13.1.5 ([ArcadeData#3905](https://redirect.github.com/markedjs/marked/issues/3905))
* [`baa78a5`](markedjs/marked@baa78a5) docs: Add marked-abc to known extensions list ([ArcadeData#3903](https://redirect.github.com/markedjs/marked/issues/3903))
* [`1aed9ac`](markedjs/marked@1aed9ac) chore(deps-dev): Bump eslint from 10.0.0 to 10.0.1 ([ArcadeData#3901](https://redirect.github.com/markedjs/marked/issues/3901))
* [`8045055`](markedjs/marked@8045055) chore: rename escape helper function ([ArcadeData#3900](https://redirect.github.com/markedjs/marked/issues/3900))
* [`bced615`](markedjs/marked@bced615) chore(release): 17.0.3 [skip ci]
* [`909fe44`](markedjs/marked@909fe44) fix: escape image alt text ([ArcadeData#3896](https://redirect.github.com/markedjs/marked/issues/3896))
* [`eb8ba2b`](markedjs/marked@eb8ba2b) chore(deps-dev): Bump `@​semantic-release/github` from 12.0.5 to 12.0.6 ([ArcadeData#3897](https://redirect.github.com/markedjs/marked/issues/3897))
* Additional commits viewable in [compare view](markedjs/marked@v15.0.12...v17.0.4)

Maintainer changes

This version was pushed to npm by [GitHub Actions](<https://www.npmjs.com/~GitHub> Actions), a new releaser for marked since your current version.

  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=marked&package-manager=npm\_and\_yarn&previous-version=15.0.12&new-version=17.0.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants