Skip to content

Conversation

@alinabuzachis
Copy link
Contributor

@alinabuzachis alinabuzachis commented Oct 31, 2025

SUMMARY

Add the mcp connection plugin

Depends On #7

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

mcp

@softwarefactory-project-zuul
Copy link

@softwarefactory-project-zuul
Copy link

@alinabuzachis alinabuzachis force-pushed the connection/plugin/mcp branch 2 times, most recently from 6e38155 to 3cac395 Compare October 31, 2025 09:54
@softwarefactory-project-zuul
Copy link

@softwarefactory-project-zuul
Copy link

@softwarefactory-project-zuul
Copy link

@softwarefactory-project-zuul
Copy link

Copy link
Contributor

@abikouo abikouo left a comment

Choose a reason for hiding this comment

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

It will be worth adding unit tests for the single method _load_server_from_manifest() and _create_transport()

mkdir
ln
rm
ansible-galaxy
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be added as depency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I do not include ansible_galaxy here, it will complain:

linters: failed with ansible-galaxy is not allowed, use allowlist_externals to allow it linters: FAIL code 1 (6.99 seconds)

Comment on lines +244 to +259
def close(self) -> None:
"""Terminate the persistent connection and reset state."""
display.vvv("[mcp] Closing MCP connection")

self._close_client()
super().close() # sets _conn_closed, _connected

def _close_client(self) -> None:
"""Close the MCPClient if it exists and reset the reference."""
if not self._client:
display.vvv("[mcp] No MCP client to close")
return

Copy link
Contributor

Choose a reason for hiding this comment

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

why not merging the 2 methods into a single one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_close_client() exclusively handle the dependency-specific shutdown and error handling for the MCPClient, while close() is a high-level method responsible for coordinating the overall cleanup and calling super().close() for base class state management.

type: dict
vars:
- name: ansible_mcp_mcp_server_env
mcp_bearer_token:
Copy link
Member

Choose a reason for hiding this comment

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

Can we also read this from an MCP_BEARER_TOKEN env var?


return manifest[server_name]

def _create_transport(self, server_name: str, server_info: dict):
Copy link
Member

Choose a reason for hiding this comment

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

The type hinting should show a return type of Transport.

@alinabuzachis alinabuzachis force-pushed the connection/plugin/mcp branch 7 times, most recently from 73abd34 to e11669a Compare November 4, 2025 15:28
@softwarefactory-project-zuul
Copy link

- Both stdio and Streamable HTTP transport methods are supported.
- All tasks using this connection plugin are run on the Ansible control node.
options:
mcp_server_name:
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, just now noticing. We should probably remove the mcp_ prefix from these options so we don't end up with ansible_mcp_mcp_ for config vars.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, makes sense, removed!

mandar242 and others added 12 commits November 4, 2025 17:46
Signed-off-by: Alina Buzachis <[email protected]>
Signed-off-by: Alina Buzachis <[email protected]>
Signed-off-by: Alina Buzachis <[email protected]>
Signed-off-by: Alina Buzachis <[email protected]>
Signed-off-by: Alina Buzachis <[email protected]>
Signed-off-by: Alina Buzachis <[email protected]>
Signed-off-by: Alina Buzachis <[email protected]>
Signed-off-by: Alina Buzachis <[email protected]>
@softwarefactory-project-zuul
Copy link

@alinabuzachis alinabuzachis merged commit abad8a5 into ansible-collections:main Nov 4, 2025
40 checks passed
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.

5 participants