Improved MCP server with init instructions and server list in query error#3896
Improved MCP server with init instructions and server list in query error#3896ExtReMLapin wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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.
| final Set<String> installed = new TreeSet<>(server.getDatabaseNames()); | ||
| final Set<String> allowed = user.getAuthorizedDatabases(); | ||
| if (!allowed.contains("*")) | ||
| installed.retainAll(allowed); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
| 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); |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 4 |
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
|
@ExtReMLapin can you rebase and push again? thanks |
|
Done ! |
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
supersede by #3966 Thank you for your contribution! |
…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. [](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)
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