refactor: update references to CapiscioMCPServer.connect() API#10
Merged
Conversation
- README.md: MCPServerIdentity.from_env() → CapiscioMCPServer.connect() - guard.py: update from_env() docstring to reference connect() pattern
There was a problem hiding this comment.
Pull request overview
Updates documentation cross-references to align with the newer one-liner connect() APIs in the CapiscIO ecosystem (replacing mentions of deprecated from_env() initializers in other packages).
Changes:
- README: Updates the cross-reference in the “Using Environment Variables” section to point to
CapiscIO.connect()/CapiscioMCPServer.connect(). CapiscioGuard.from_env()docstring: Updates referenced external APIs fromfrom_env()toconnect().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| README.md | Updates the external API cross-reference to the newer connect() naming. |
| langchain_capiscio/guard.py | Updates the from_env() docstring to reference connect() APIs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reword to avoid implying from_env() mirrors connect() — it's an env-var convenience initializer, not a connect/handshake call.
Add connect() classmethod that eagerly connects to the CapiscIO registry, matching the CapiscIO.connect() and CapiscioMCPServer.connect() patterns used across the ecosystem. - connect() reads env vars as fallbacks, validates api_key upfront - from_env() now delegates to connect() (kept as convenience alias) - README updated to feature connect() as the primary API - 6 new unit tests for connect() and from_env() delegation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (2)
tests/unit/test_guard.py:186
- This test does not isolate
CAPISCIO_DEV_MODEfrom the process environment. If it’s set externally,CapiscioGuard.connect(..., mode="log")will forwarddev_mode=Trueand break theassert_called_once_with(...)expectation. Consider clearingCAPISCIO_DEV_MODE(and any other relevant CAPISCIO_* vars) within the test.
mock_sdk = MagicMock()
mock_sdk.CapiscIO.connect.return_value = fake_identity
mock_sdk.SecurityConfig.development.return_value = FakeConfig("warn")
with patch.dict(sys.modules, {"capiscio_sdk": mock_sdk}):
guard = CapiscioGuard.connect(
api_key="cap_explicit",
mode="log",
name="my-agent",
server_url="https://dev.registry.capisc.io",
)
assert guard._initialized is True
assert guard.mode == "log"
mock_sdk.CapiscIO.connect.assert_called_once_with(
"cap_explicit",
name="my-agent",
server_url="https://dev.registry.capisc.io",
)
tests/unit/test_guard.py:250
- Like the other connect tests, this assertion assumes no extra env-derived kwargs (e.g.
CAPISCIO_AGENT_NAME/CAPISCIO_SERVER_URL) are present. If those env vars are set in the runner,CapiscioGuard.connect()will forward them and the call assertion will fail. Consider explicitly clearing them in the test setup alongsideCAPISCIO_API_KEY/CAPISCIO_DEV_MODE.
old_key = os.environ.get("CAPISCIO_API_KEY")
old_dev = os.environ.get("CAPISCIO_DEV_MODE")
os.environ["CAPISCIO_API_KEY"] = "cap_test"
os.environ["CAPISCIO_DEV_MODE"] = "true"
try:
with patch.dict(sys.modules, {"capiscio_sdk": mock_sdk}):
CapiscioGuard.connect()
finally:
if old_key is not None:
os.environ["CAPISCIO_API_KEY"] = old_key
else:
os.environ.pop("CAPISCIO_API_KEY", None)
if old_dev is not None:
os.environ["CAPISCIO_DEV_MODE"] = old_dev
else:
os.environ.pop("CAPISCIO_DEV_MODE", None)
mock_sdk.CapiscIO.connect.assert_called_once_with(
"cap_test",
dev_mode=True,
)
- Change dev_mode param from bool=False to bool|None=None so explicit False overrides CAPISCIO_DEV_MODE env var - Fix from_env() docstring to mention kwargs override env vars - Fix README constructor signature to show keyword-only args - Isolate tests from runner env vars using patch.dict(os.environ) - Add test for dev_mode=False overriding env var
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Update references from deprecated
MCPServerIdentity.from_env()/CapiscIO.from_env()to the newCapiscioMCPServer.connect()/CapiscIO.connect()one-liner APIs.Files Changed
README.md— Update API cross-referencelangchain_capiscio/guard.py— Updatefrom_env()docstringRelated PRs
capiscio-mcp-python:
feat/connect-one-linercapiscio-docs:
refactor/connect-api-rename"