7373# whether the field was absent from the schema's `required` list. It is an internal
7474# marker, not part of the served schema, so it is stripped before a schema is
7575# handed to a model.
76- _INTERNAL_SCHEMA_KEYS = frozenset ({"nullable" })
77-
78-
7976@dataclass
8077class McpToolDefinition :
8178 """A tool exactly as the MCP server listed it."""
@@ -357,24 +354,6 @@ async def _call_within_deadline() -> JsonDict:
357354 raise _describe_mcp_failure (exc , endpoint ) from exc
358355
359356
360- def _strip_internal_keys (schema : Any ) -> Any :
361- """Recursively drop the SDK's internal markers from a property schema.
362-
363- Everything else is preserved verbatim: ``format``, ``pattern``, ``default``,
364- ``minimum``/``maximum``, ``oneOf``/``anyOf``, nested ``required`` and any
365- keyword the server sends that this SDK has never heard of.
366- """
367- if isinstance (schema , dict ):
368- return {
369- key : _strip_internal_keys (value )
370- for key , value in schema .items ()
371- if key not in _INTERNAL_SCHEMA_KEYS
372- }
373- if isinstance (schema , list ):
374- return [_strip_internal_keys (item ) for item in schema ]
375- return schema
376-
377-
378357class StackOneTool (BaseModel ):
379358 """A single tool: its served schema plus the request needed to execute it."""
380359
@@ -385,14 +364,7 @@ class StackOneTool(BaseModel):
385364 _api_key : str = PrivateAttr ()
386365 _account_id : str | None = PrivateAttr (default = None )
387366
388- @property
389- def connector (self ) -> str :
390- """Extract connector from tool name.
391367
392- Tool names follow the format: {connector}_{action}_{entity}
393- e.g., 'bamboohr_create_employee' -> 'bamboohr'
394- """
395- return self .name .split ("_" )[0 ].lower ()
396368
397369 def __init__ (
398370 self ,
@@ -470,13 +442,9 @@ def _sanitise_headers(self, supplied: dict[str, Any] | None) -> dict[str, str]:
470442
471443 The allowlist is the served schema itself, so this needs no maintenance: today
472444 zero of the served actions declare a ``headers_*`` property, and the RPC server
473- ignores the envelope's ``headers`` object outright — but the day an action
474- genuinely needs a header, it works with no SDK release.
475-
476- Lives on the base class because both execution paths need it: the RPC tool
477- builds the envelope's headers, and the MCP tool — what search_execute mode
478- returns, and so what the documented search()/execute() flow uses — forwards the
479- model's headers object into tools/call.
445+ ignores the envelope's ``headers`` object outright. (Note: on the MCP path for
446+ meta tools, headers are always dropped because the target action's schema is not
447+ fetched ahead of execution to build an allowlist.)
480448 """
481449 allowed = {
482450 prop [len ("headers_" ) :].casefold ()
@@ -642,20 +610,23 @@ def to_openai_function(self) -> JsonDict:
642610
643611 for name , prop in self .parameters .properties .items ():
644612 if isinstance (prop , dict ):
645- properties [name ] = _strip_internal_keys (prop )
646- if not prop .get ("nullable" , False ):
613+ clean_prop = dict (prop )
614+ is_nullable = clean_prop .pop ("nullable" , False )
615+ properties [name ] = clean_prop
616+ if not is_nullable :
647617 required .append (name )
648618 else :
649619 properties [name ] = {"type" : "string" }
650620 required .append (name )
651621
652- parameters : JsonDict = {
653- "type" : "object" ,
654- "properties" : properties ,
655- }
622+ parameters : JsonDict = self .parameters .model_dump ()
623+ parameters ["properties" ] = properties
656624
625+ # Only set required if there are required properties, else remove it if it existed
657626 if required :
658627 parameters ["required" ] = required
628+ else :
629+ parameters .pop ("required" , None )
659630
660631 return {
661632 "type" : "function" ,
@@ -872,6 +843,11 @@ def _split_envelope_params(
872843 # name is proof the schema is not. `any` would be satisfied by the very key
873844 # this exists to protect — a declared body field called `path_to_file`.
874845 prefixed = not named or all (_FLAT_ENVELOPE_KEY_PATTERN .match (k ) for k in named )
846+ if named and not prefixed :
847+ logger .debug (
848+ "Schema has at least one bare parameter name so flat-prefix detection "
849+ "is disabled. Every parameter will fall into the body unless explicitly nested."
850+ )
875851
876852 # Two passes so precedence is deterministic rather than following the caller's
877853 # dict order: an explicit flat_prefixed key always wins over a nested one.
@@ -1042,9 +1018,7 @@ def get_account_id(self) -> str | None:
10421018 return account_id
10431019 return None
10441020
1045- def get_connectors (self ) -> set [str ]:
1046- """Get unique connector names from all tools (lowercase)"""
1047- return {tool .connector for tool in self .tools }
1021+
10481022
10491023 def to_openai (self ) -> list [JsonDict ]:
10501024 """Convert all tools to OpenAI function format"""
0 commit comments