Skip to content

test(source/neo4j): migrate integration tests to MCP endpoint - #4179

Open
DylanVolz wants to merge 2 commits into
googleapis:mainfrom
DylanVolz:chore/neo4j-mcp-migration
Open

DylanVolz wants to merge 2 commits into
googleapis:mainfrom
DylanVolz:chore/neo4j-mcp-migration

Conversation

@DylanVolz

Copy link
Copy Markdown

Description

This PR migrates the Neo4j integration tests to use the /mcp endpoint on the MCP Toolbox Server, and adds a testcontainer fallback so the suite can run locally with Docker only.

Key Changes

  • neo4j_mcp_test.go: Migrated legacy /api tests to /mcp

    • TestNeo4jMCPListTools validates the full tools/list manifest for the six Neo4j tools configured in the test (neo4j-cypher, neo4j-execute-cypher and its read-only variant, and three neo4j-schema tools).
    • TestNeo4jMCPCallTool runs the same nine invocation cases as the legacy test over MCP JSON-RPC: simple and ad-hoc cypher, dry_run query plans, read-only enforcement, and schema extraction on an empty and a populated database (constraints, indexes, relationships).
    • Rejected invocations (invalid syntax with dry_run, and writes through the read-only tool with and without dry_run) are marked wantErr and must come back as an MCP error result (isError), not just contain error text.
    • Uses t.Cleanup for server and cmd.Close cleanup.
  • neo4j_integration_test.go: Added a container fallback and extracted shared helpers (no behavior change to the legacy test's assertions):

    • setupNeo4jInstance starts an ephemeral neo4j:5.26 container with the APOC plugin (required by the schema tool) when NEO4J_URI is unset, and restores the package-level connection variables on cleanup so each test gets its own container. CI sets NEO4J_URI, so it keeps using its existing instance.
    • getNeo4jToolsConfig builds the shared tools file; the legacy test still appends the semantic search config.
    • getNeo4jInvokeTestCases holds the shared invocation cases (toolName + args map[string]any), replacing the inline requestBody JSON strings and the unused wantStatus/wantErrorSubstring fields.
    • Raised the legacy test timeout from 1 to 5 minutes to cover container startup.

Semantic search stays in the legacy test only, since it requires a Gemini API_KEY. No shared test helpers (tests/tool.go, tests/mcp_tool.go, tests/option.go) are modified.

Verified locally against the neo4j:5.26 testcontainer: go test -count=1 -v -run TestNeo4jMCP ./tests/neo4j/ passes, and the legacy test's manifest and invoke subtests pass (its semantic search subtests need a real API_KEY, which CI provides).

PR Checklist

Thank you for opening a Pull Request! Before submitting your PR, there are a
few things you can do to make sure it goes smoothly:

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure you have manually reviewed the entire diff before requesting a
    review
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>

@DylanVolz
DylanVolz requested a review from a team as a code owner September 29, 2026 19:21
@google-cla

google-cla Bot commented Sep 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 refactors the Neo4j integration tests to run against an ephemeral container using testcontainers-go and introduces a new test suite for testing the Neo4j Model Context Protocol (MCP) server. It consolidates the test cases into a shared helper to ensure both REST and MCP interfaces are tested consistently. The feedback suggests improving the REST test execution by using http.NewRequestWithContext instead of http.Post to ensure proper context and timeout propagation.

Comment thread tests/neo4j/neo4j_integration_test.go Outdated
@AlexTalreja

Copy link
Copy Markdown
Contributor

/gcbrun

@DylanVolz
DylanVolz force-pushed the chore/neo4j-mcp-migration branch from b33edc8 to 1cd2e82 Compare October 16, 2026 23:36

This branch has not been deployed

No deployments
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.

3 participants