Skip to content

NIFI-16524 Add InvokeMcpServer Processor and MCP Client Service - #11863

Open
Vinz2168 wants to merge 4 commits into
apache:mainfrom
Vinz2168:NIFI-16524
Open

Vinz2168 wants to merge 4 commits into
apache:mainfrom
Vinz2168:NIFI-16524

Conversation

@Vinz2168

Copy link
Copy Markdown
Contributor

Summary

NIFI-16524

This adds a new nifi-mcp-bundle that lets NiFi act as a client of
Model Context Protocol (MCP) servers, so
flows can consume MCP tools, resources and prompts deterministically,
without an LLM in the loop.

  • McpClientService (API) and StandardMcpClientService: one MCP session
    per service, shared by all referencing processors, over Streamable HTTP or
    SSE, with an optional SSL Context Service (TLS/mTLS), Bearer Token and
    sensitive dynamic properties sent as HTTP headers. It connects lazily if
    the server is down when the service is enabled, reconnects after transport
    failures, and supports config verification.
  • InvokeMcpServer: Call Tool, Read Resource, Get Prompt and List
    Tools/Resources/Prompts. Arguments come from FlowFile content or from a
    property with Expression Language. Output can be the full result, text
    only, or the tool's structuredContent. Relationships: success,
    tool error (isError: true), original and failure.
  • Dependencies: the MCP Java SDK (MIT) plus Reactor, Jackson 3 (managed by
    the NiFi BOM), json-schema-validator, SnakeYAML Engine, ITU (Apache 2.0)
    and Reactive Streams (CC0). All are documented in the NAR's
    LICENSE/NOTICE.
  • The NAR is left out of the default assembly behind an optional
    include-mcp profile.
  • STDIO transport is intentionally out of scope for this PR because of its
    security implications.

Unit tests run the processor against a fake service, and the service against
a real in-process MCP Java SDK server on Jetty, so no network is needed.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000
  • Pull request contains commits signed with a registered key indicating Verified status

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using ./mvnw clean install -P contrib-check (bundle modules)
    • JDK 21
    • JDK 25

Built and tested locally on JDK 26; relying on CI for JDK 21 and 25.

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

🤖 Generated with Claude Code

@exceptionfactory exceptionfactory 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.

Thanks for proposing these new MCP integration components @Vinz2168.

This seems generic enough to fit within general goals for community-maintained capabilities, and the overall module structure looks sound.

There are some conventional items to address like unnecessary public modifiers on Property Descriptors and using multiline text blocks instead of concatenation for descriptions, which are easily adjusted.

On the test side, although the project is not completely consistent, the OkHttp MockWebServer library should be used for HTTP server testing instead of Jetty to provide better control over request and response handling.

As this is a larger effort, it may take some time to review fully, but those or some initial items to address.

@Vinz2168

Copy link
Copy Markdown
Contributor Author

Thanks for the review @exceptionfactory! Pushed an update addressing the initial items:

  • Removed the legacy HTTP+SSE transport, along with the Transport property, so Streamable HTTP is the only supported transport
  • Removed unnecessary public modifiers on Property Descriptors and Relationships
  • Replaced concatenated descriptions with multiline text blocks
  • Replaced Jetty with OkHttp MockWebServer in the client service tests, using a Dispatcher that answers the MCP JSON-RPC messages directly

@Vinz2168

Copy link
Copy Markdown
Contributor Author

Pushed 689cba5 addressing the review feedback. Could a maintainer please approve the workflows when convenient? Thanks!

@Vinz2168

Vinz2168 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Pushed cc512a8 to fix a timing-dependent assertion in StandardMcpClientServiceTest.reconnectsAfterServerRestartInvalidatesTheSession, which failed on the Windows and Corretto JDK 21 builds. After a 404 for an unknown session, the MCP SDK can re-initialize on its own before the service drops the session, so the test now accepts one or two new handshakes. The separate integration-tests failure is unrelated: MongoDBControllerServiceIT and MongoDBLookupServiceIT timed out connecting to the MongoDB test container.

@Vinz2168

Copy link
Copy Markdown
Contributor Author

The previous CI failure was unrelated to this change (Testcontainers MongoDB ITs in nifi-mongodb-services could not connect to the container: MongoSocketOpenException: Connection refused). I pushed an empty commit to retrigger CI — could a committer please approve the workflow run? Thanks!

@Vinz2168

Copy link
Copy Markdown
Contributor Author

All checks passed except docker-tests, which failed before compiling because the Develocity Maven extension could not be resolved from Maven Central (infrastructure issue). Could that job be re-run when convenient? The review feedback has been addressed in 689cba5 and cc512a8, ready for another look. Thanks!

@Vinz2168

Vinz2168 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Hi @exceptionfactory, all points from your review have been addressed in 689cba5 (SSE transport removed, package-private descriptors, text blocks, mockwebserver3 instead of Jetty). All checks pass except docker-tests, which failed resolving com.gradle:develocity-maven-extension:2.6.0 from Maven Central; that job is green on main again since 10/28, so a re-run should clear it. Could you take another look when you have a moment? Thanks!

Vinz2168 and others added 4 commits November 19, 2026 08:45
- Add McpClientService API and StandardMcpClientService supporting the
  Streamable HTTP and SSE transports, with optional SSL Context Service,
  Bearer Token and sensitive dynamic properties sent as HTTP headers
- Add InvokeMcpServer supporting Call Tool, Read Resource, Get Prompt and
  List Tools, Resources and Prompts, with configurable output content
- Add optional include-mcp profile to nifi-assembly

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Removed legacy HTTP+SSE transport and Transport property
- Removed unnecessary public modifiers on Property Descriptors and Relationships
- Replaced concatenated descriptions with text blocks
- Replaced Jetty with OkHttp MockWebServer in client service tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Replaced deprecated httpRequestCustomizer with addHttpRequestCustomizer
- Declared pattern variables final

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vinz2168

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest main and updated the MCP Java SDK from 2.0.1 to 2.2.0, replacing the deprecated httpRequestCustomizer with addHttpRequestCustomizer. The new FinalPatternVariable Checkstyle rule on main also required declaring pattern variables final. Ready for another look whenever you have time, thanks!

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