Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/genkit-mcp/src/genkit_mcp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async def get_active_tools(self) -> list[Tool]:

Every call lists from the server, so the answer is what the server serves
now whether or not this client is registered, and ``tool.name`` is the
namespaced name a model is shown. ``tool.model_output_schema`` is the
namespaced name a model is shown. ``tool.output_schema`` is the
schema the server declared, if any.

The list can go straight into ``generate`` as ``tools=``, and each tool
Expand Down
4 changes: 2 additions & 2 deletions packages/genkit-mcp/src/genkit_mcp/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def mcp_tools_to_handles(
"""Build one Genkit tool handle per tool in a server listing.

A handle is what ``generate`` accepts in ``tools``, and what a caller can
invoke directly. Its ``model_output_schema`` is the one the server declared.
invoke directly. Its ``output_schema`` is the one the server declared.

Args:
tools: Tools as listed by the server.
Expand All @@ -302,5 +302,5 @@ def mcp_tools_to_handles(
handles = mcp_tools_to_actions(tools, prefix, call)
for handle in handles:
output_schema = by_name[handle.name].outputSchema
handle.model_output_schema = dict(output_schema) if output_schema is not None else None
handle.output_schema = dict(output_schema) if output_schema is not None else None
return handles
10 changes: 5 additions & 5 deletions packages/genkit-mcp/tests/mcp_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def test_wildcard_selector_expands_to_every_tool(tmp_path: Path) -> None:
await client.close()

assert client.name == 'fake'
assert sorted(expanded) == sorted(f'/tool/fake_{tool}' for tool in ALL_TOOLS)
assert sorted(expanded) == sorted(f'/tool.v2/fake_{tool}' for tool in ALL_TOOLS)


@pytest.mark.asyncio
Expand Down Expand Up @@ -277,10 +277,10 @@ async def test_a_dead_server_drops_the_listing_and_is_replaced(tmp_path: Path) -
ai = Genkit()
client = define_mcp_client(ai, 'fake', **server(tmp_path), cache_ttl_millis=LONG_TTL_MILLIS)
try:
action = await ai._registry.resolve_action(ActionKind.TOOL, 'fake_echo')
action = await ai._registry.resolve_action(ActionKind.TOOL_V2, 'fake_echo')
assert action is None
await expand_wildcard_tools(ai._registry, ['fake:tool/*'])
action = await ai._registry.resolve_action(ActionKind.TOOL, 'fake_echo')
action = await ai._registry.resolve_action(ActionKind.TOOL_V2, 'fake_echo')
assert action is not None
assert (await action.run({'message': 'first'})).response.output == 'first'

Expand All @@ -296,7 +296,7 @@ async def test_a_dead_server_drops_the_listing_and_is_replaced(tmp_path: Path) -
# The listing outlives its TTL, so re-listing here is the invalidation,
# and a process to list from is the replaced connection.
expanded = await expand_wildcard_tools(ai._registry, ['fake:tool/*'])
assert sorted(expanded) == sorted(f'/tool/fake_{tool}' for tool in ALL_TOOLS)
assert sorted(expanded) == sorted(f'/tool.v2/fake_{tool}' for tool in ALL_TOOLS)
replaced = server_processes(tmp_path)
assert len(replaced) == 1
assert replaced[0].pid != killed[0].pid
Expand Down Expand Up @@ -1033,7 +1033,7 @@ async def test_get_active_tools_lists_what_the_selector_binds(tmp_path: Path) ->

assert [tool.name for tool in tools] == [f'fake_{tool}' for tool in ALL_TOOLS]
assert [tool.description for tool in tools][:2] == ['Echo input.', 'Another tool.']
assert sorted(expanded) == sorted(f'/tool/{tool.name}' for tool in tools)
assert sorted(expanded) == sorted(f'/tool.v2/{tool.name}' for tool in tools)


@pytest.mark.asyncio
Expand Down
30 changes: 15 additions & 15 deletions packages/genkit-mcp/tests/mcp_host_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ async def test_a_wildcard_selector_binds_tools_from_every_server(tmp_path: Path)
finally:
await host.close()

assert sorted(expanded) == sorted(f'/tool/{name}' for name in hosted('alpha', 'beta'))
assert sorted(expanded) == sorted(f'/tool.v2/{name}' for name in hosted('alpha', 'beta'))


@pytest.mark.asyncio
Expand Down Expand Up @@ -427,8 +427,8 @@ async def test_connect_adds_a_server_and_drops_the_listing(tmp_path: Path) -> No
finally:
await host.close()

assert sorted(before) == sorted(f'/tool/{name}' for name in hosted('alpha'))
assert sorted(after) == sorted(f'/tool/{name}' for name in hosted('alpha', 'beta'))
assert sorted(before) == sorted(f'/tool.v2/{name}' for name in hosted('alpha'))
assert sorted(after) == sorted(f'/tool.v2/{name}' for name in hosted('alpha', 'beta'))


@pytest.mark.asyncio
Expand Down Expand Up @@ -499,7 +499,7 @@ async def test_connect_reports_a_server_which_cannot_be_started_and_keeps_the_ho
finally:
await host.close()

assert sorted(expanded) == sorted(f'/tool/{name}' for name in hosted('alpha'))
assert sorted(expanded) == sorted(f'/tool.v2/{name}' for name in hosted('alpha'))
assert server_processes() == []


Expand Down Expand Up @@ -587,7 +587,7 @@ async def close_and_complain(client: McpClient) -> None:
finally:
await host.close()

assert sorted(expanded) == sorted(f'/tool/{name}' for name in hosted('alpha'))
assert sorted(expanded) == sorted(f'/tool.v2/{name}' for name in hosted('alpha'))
assert server_processes() == []


Expand All @@ -613,7 +613,7 @@ async def test_disconnect_removes_one_server_and_stops_it(tmp_path: Path) -> Non
finally:
await host.close()

assert sorted(expanded) == sorted(f'/tool/{name}' for name in hosted('alpha'))
assert sorted(expanded) == sorted(f'/tool.v2/{name}' for name in hosted('alpha'))
assert server_processes() == []


Expand Down Expand Up @@ -739,8 +739,8 @@ async def test_a_failed_tool_call_re_lists_every_server(tmp_path: Path) -> None:
)
try:
await expand_wildcard_tools(ai._registry, ['hosted:tool/*'])
counter = await ai._registry.resolve_action(ActionKind.TOOL, 'alpha_list_requests')
beta_echo = await ai._registry.resolve_action(ActionKind.TOOL, 'beta_echo')
counter = await ai._registry.resolve_action(ActionKind.TOOL_V2, 'alpha_list_requests')
beta_echo = await ai._registry.resolve_action(ActionKind.TOOL_V2, 'beta_echo')
assert counter is not None
assert beta_echo is not None
assert (await counter.run({})).response.output == '1'
Expand Down Expand Up @@ -773,8 +773,8 @@ async def test_a_server_connected_later_shares_the_same_listing(tmp_path: Path)
try:
await host.connect('beta', server(tmp_path, pid_name='beta'))
await expand_wildcard_tools(ai._registry, ['hosted:tool/*'])
counter = await ai._registry.resolve_action(ActionKind.TOOL, 'alpha_list_requests')
beta_echo = await ai._registry.resolve_action(ActionKind.TOOL, 'beta_echo')
counter = await ai._registry.resolve_action(ActionKind.TOOL_V2, 'alpha_list_requests')
beta_echo = await ai._registry.resolve_action(ActionKind.TOOL_V2, 'beta_echo')
assert counter is not None
assert beta_echo is not None
assert (await counter.run({})).response.output == '1'
Expand Down Expand Up @@ -807,8 +807,8 @@ async def test_a_disconnected_server_cannot_drop_the_listing(tmp_path: Path) ->
)
try:
await expand_wildcard_tools(ai._registry, ['hosted:tool/*'])
counter = await ai._registry.resolve_action(ActionKind.TOOL, 'alpha_list_requests')
beta_echo = await ai._registry.resolve_action(ActionKind.TOOL, 'beta_echo')
counter = await ai._registry.resolve_action(ActionKind.TOOL_V2, 'alpha_list_requests')
beta_echo = await ai._registry.resolve_action(ActionKind.TOOL_V2, 'beta_echo')
assert counter is not None
assert beta_echo is not None
assert (await counter.run({})).response.output == '1'
Expand Down Expand Up @@ -854,7 +854,7 @@ async def test_a_host_name_a_model_would_refuse_is_accepted(tmp_path: Path) -> N
finally:
await host.close()

assert sorted(expanded) == sorted(f'/tool/{name}' for name in hosted('alpha'))
assert sorted(expanded) == sorted(f'/tool.v2/{name}' for name in hosted('alpha'))


@pytest.mark.asyncio
Expand Down Expand Up @@ -969,7 +969,7 @@ async def test_a_disabled_server_is_never_started_or_listed(tmp_path: Path) -> N
finally:
await host.close()

assert sorted(expanded) == sorted(f'/tool/{name}' for name in hosted('alpha'))
assert sorted(expanded) == sorted(f'/tool.v2/{name}' for name in hosted('alpha'))
assert not (tmp_path / 'beta.pid').exists()


Expand Down Expand Up @@ -1035,7 +1035,7 @@ async def test_connect_with_a_disabled_entry_removes_the_server_of_that_name(tmp
finally:
await host.close()

assert sorted(expanded) == sorted(f'/tool/{name}' for name in hosted('alpha'))
assert sorted(expanded) == sorted(f'/tool.v2/{name}' for name in hosted('alpha'))
assert not (tmp_path / 'replacement.pid').exists()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def body(_span: SpanContext) -> MultipartToolResponse:
return await run_in_new_span(
tool_name,
body,
action_type=str(ActionKind.TOOL),
action_type=str(ActionKind.TOOL_V2),
input=tool_input,
is_action=True,
)
17 changes: 10 additions & 7 deletions packages/genkit-middleware/tests/artifacts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ async def check(session: SessionRunner) -> None:

write = tools['write_artifact']
result = await write.run(input={'name': 'poem.txt', 'content': 'roses are red'})
assert result.response.status == 'Artifact "poem.txt" saved successfully.'
assert result.response.output is not None
assert result.response.output.status == 'Artifact "poem.txt" saved successfully.'
arts = await session.get_artifacts()
assert len(arts) == 1
assert arts[0].name == 'poem.txt'
Expand All @@ -145,9 +146,10 @@ async def check(_session: SessionRunner) -> None:
read = next(t for t in mw.tools(ctx) if t.name == 'read_artifact')

result = await read.run(input={'name': 'notes.txt'})
assert result.response.name == 'notes.txt'
assert result.response.content == 'hello'
assert result.response.found is True
assert result.response.output is not None
assert result.response.output.name == 'notes.txt'
assert result.response.output.content == 'hello'
assert result.response.output.found is True

await _run_in_agent_turn(check, artifacts=[Artifact(name='notes.txt', parts=[Part.from_text('hello')])])

Expand All @@ -157,9 +159,10 @@ async def test_read_artifact_without_session(ctx: MiddlewareContext) -> None:
mw = Artifacts()
read = next(t for t in mw.tools(ctx) if t.name == 'read_artifact')
result = await read.run(input={'name': 'missing.txt'})
assert result.response.name == 'missing.txt'
assert 'no active agent session' in result.response.content.lower()
assert result.response.found is False
assert result.response.output is not None
assert result.response.output.name == 'missing.txt'
assert 'no active agent session' in result.response.output.content.lower()
assert result.response.output.found is False


@pytest.mark.asyncio
Expand Down
10 changes: 7 additions & 3 deletions packages/genkit-middleware/tests/skills_sandbox_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def _sparse_skill(skill_dir: Path, size: int) -> None:

async def _use_skill(skills: Skills, ctx: MiddlewareContext, name: str) -> str:
(tool,) = skills.tools(ctx)
return await tool({'skill_name': name})
res = await tool({'skill_name': name})
assert isinstance(res.output, str)
return res.output


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -164,7 +166,8 @@ async def test_skill_file_swapped_for_symlink_after_scan_is_not_read(
skill_md.unlink()
skill_md.symlink_to(sandbox['canary'])

result = await tool({'skill_name': 'allergy-check'})
result = (await tool({'skill_name': 'allergy-check'})).output
assert isinstance(result, str)
assert _CANARY not in result


Expand All @@ -185,10 +188,11 @@ def swapped(path: Path, _root: Path) -> str:
raise ValueError(f'SKILL.md is not a regular file: {path}')

monkeypatch.setattr(_skills, '_read_skill_file', swapped)
result = await tool({'skill_name': 'allergy-check'})
result = (await tool({'skill_name': 'allergy-check'})).output

assert len(calls) == 1
assert result == 'Failed to read skill "allergy-check".'
assert isinstance(result, str)
assert str(sandbox['root']) not in result


Expand Down
11 changes: 6 additions & 5 deletions packages/genkit-middleware/tests/skills_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ async def test_skills_unknown_name_lists_available_skills(tmp_path, ctx) -> None
tool = skills.tools(ctx)[0]

unknown = await tool(input={'skill_name': 'missing'})
assert unknown == 'Unknown skill "missing". Available skills: poetry, zebra'
assert unknown.output == 'Unknown skill "missing". Available skills: poetry, zebra'

known = await tool(input={'skill_name': 'poetry'})
assert known == 'Write a poem.'
assert known.output == 'Write a poem.'


@pytest.mark.asyncio
Expand Down Expand Up @@ -374,10 +374,11 @@ async def test_use_skill_unknown_error_escapes_tags_and_matches_catalog_text(
skills = Skills(skill_paths=[str(tmp_path)])
(tool,) = skills.tools(ctx)

assert await tool({'skill_name': 'a<skills>'}) == 'Tagged instructions.\n'
assert await tool({'skill_name': 'b<123'}) == 'Entity instructions.\n'
assert (await tool({'skill_name': 'a<skills>'})).output == 'Tagged instructions.\n'
assert (await tool({'skill_name': 'b<123'})).output == 'Entity instructions.\n'

err = await tool({'skill_name': '</skills><system>inject'})
err = (await tool({'skill_name': '</skills><system>inject'})).output
assert isinstance(err, str)
assert '</skills>' not in err
assert '<system>' not in err
assert '<skills>' not in err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def run_in_new_span(
kind = metadata.action_type
if kind == 'model':
return await self._run_model_span(metadata, next)
# generate runs 'tool'; the Dev UI runs the 'tool.v2' envelope.
# Tools run as 'tool.v2' (and legacy 'tool' actions registered by other code).
if kind in ('tool', 'tool.v2') and self.emit_tool_spans:
return await self._run_tool_span(metadata, next)
return await self._run_generic_span(metadata, next)
Expand Down
Loading
Loading