Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements the get_observations tool for MCP v2, enabling the retrieval of numerical observations and source metadata for statistical variables. It introduces shared SDMX helpers, date parsing, and facet ranking logic, alongside comprehensive unit and integration tests. The review feedback highlights opportunities to simplify the code by removing redundant nil checks on protobuf messages, as Go protobuf getters are nil-safe.
|
|
||
| for _, dcid := range dcids { | ||
| p := &nodeProperties{} | ||
| if nodeResp != nil && nodeResp.GetData() != nil { |
There was a problem hiding this comment.
In Go, defensive nil checks before calling generated protobuf getters are unnecessary because protobuf getters are nil-safe. Since nodeResp.GetData() is safe to call even if nodeResp is nil, the nodeResp != nil check can be safely omitted.
| if nodeResp != nil && nodeResp.GetData() != nil { | |
| if nodeResp.GetData() != nil { |
References
- In Go, defensive nil checks before calling generated protobuf getters are unnecessary because protobuf getters are nil-safe.
| if fullResult != nil { | ||
| if shapeSlots := extractShapeDimensionSlots(fullResult.GetShape()); len(shapeSlots) > 0 { | ||
| return shapeSlots | ||
| } | ||
| if slots := extractDimensionSlots(fullResult); len(slots) > 0 { | ||
| return slots | ||
| } | ||
| } |
There was a problem hiding this comment.
In Go, defensive nil checks before calling generated protobuf getters are unnecessary because protobuf getters are nil-safe. Since fullResult.GetShape() is safe to call even if fullResult is nil, and extractDimensionSlots also handles a nil result safely, the fullResult != nil check can be safely omitted.
if shapeSlots := extractShapeDimensionSlots(fullResult.GetShape()); len(shapeSlots) > 0 {
return shapeSlots
}
if slots := extractDimensionSlots(fullResult); len(slots) > 0 {
return slots
}References
- In Go, defensive nil checks before calling generated protobuf getters are unnecessary because protobuf getters are nil-safe.
5c75d69 to
4a0aebb
Compare
Added the
get_observationstool to MCP v2 (/mcp/preview), consolidating explicit-entity, child-entity, and multi-entity observation lookups into a single tool.V2GetObservationstoagent.Serviceand wiredget_observationsinto the MCP v2 server:variable_dcidsaccepts 1 to 10 statistical variables sharingobservation_propertiesin oneSdmxDataquery (1 to 2 withchild_entity_type_dcid, or 1 withsource_override).entity_dcidsaccepts 1 to 20 entities (or 1 parent entity withchild_entity_type_dcid).entity_property(defaultobservationAbout) andadditional_entities(up to 2 properties, 1 to 20 DCIDs each) constrain multi-entity variables, with omitted counterpart properties left unconstrained.datesupportslatest(pushed down asTIME_PERIOD="LATEST"),all(explicit entities only), ISO dates (YYYY,YYYY-MM,YYYY-MM-DD), andrange(explicit or inferred whendateis omitted alongsidedate_range_startordate_range_end; child-entity ranges requiredate_range_start).entity_metadatatable across active entities and per-variableobservationsin request order:source_metadata(source_id,import_nameandprovenance_urlfrom provenance->[name, url]with provenance DCID fallback,unit,scaling_factor,measurement_method,observation_period) andalternative_sources(withentities_found_countwhen multiple entities or entity tuples have data).notemessages when a variable has no observations for the requested entities,source_override, or date window.get_observationsvalidation and SDMX rejection diagnostics inv2_tool_errors.goandv2_observations.gowithout leaking internal Spanner or SDMX error strings.instructions/v2/tools/get_observations.mdand updatedinstructions/v2/server.mdfor theresolve_entities->search_indicators->get_observationsworkflow.