|
10 | 10 |
|
11 | 11 | import pandas as pd |
12 | 12 | from everyrow.api_utils import handle_response |
| 13 | +from everyrow.built_in_lists import list_built_in_datasets, use_built_in_list |
13 | 14 | from everyrow.constants import EveryrowError |
14 | 15 | from everyrow.generated.api.billing import get_billing_balance_billing_get |
15 | 16 | from everyrow.generated.api.tasks import get_task_status_tasks_task_id_status_get |
|
35 | 36 | from everyrow_mcp.config import settings |
36 | 37 | from everyrow_mcp.models import ( |
37 | 38 | AgentInput, |
| 39 | + BrowseListsInput, |
38 | 40 | CancelInput, |
39 | 41 | DedupeInput, |
40 | 42 | ForecastInput, |
|
47 | 49 | SingleAgentInput, |
48 | 50 | StdioResultsInput, |
49 | 51 | UploadDataInput, |
| 52 | + UseListInput, |
50 | 53 | _schema_to_model, |
51 | 54 | ) |
52 | 55 | from everyrow_mcp.result_store import ( |
@@ -102,6 +105,124 @@ async def _check_task_ownership(task_id: str) -> list[TextContent] | None: |
102 | 105 | return None |
103 | 106 |
|
104 | 107 |
|
| 108 | +@mcp.tool( |
| 109 | + name="everyrow_browse_lists", |
| 110 | + structured_output=False, |
| 111 | + annotations=ToolAnnotations( |
| 112 | + title="Browse Reference Lists", |
| 113 | + readOnlyHint=True, |
| 114 | + destructiveHint=False, |
| 115 | + idempotentHint=True, |
| 116 | + openWorldHint=False, |
| 117 | + ), |
| 118 | +) |
| 119 | +async def everyrow_browse_lists( |
| 120 | + params: BrowseListsInput, ctx: EveryRowContext |
| 121 | +) -> list[TextContent]: |
| 122 | + """Browse available reference lists of well-known entities. |
| 123 | +
|
| 124 | + Includes company lists (S&P 500, FTSE 100, Russell 3000, sector breakdowns |
| 125 | + like Global Banks or Semiconductor companies), geographic lists (all countries, |
| 126 | + EU members, US states, major cities), people (billionaires, heads of state, |
| 127 | + AI leaders), institutions (top universities, regulators), and infrastructure |
| 128 | + (airports, ports, power stations). |
| 129 | +
|
| 130 | + Use this when the user's analysis involves a well-known group that we might |
| 131 | + already have a list for. Returns names, fields, and artifact_ids to pass to |
| 132 | + everyrow_use_list. |
| 133 | +
|
| 134 | + Call with no parameters to see all available lists, or use search/category |
| 135 | + to narrow results. |
| 136 | + """ |
| 137 | + client = _get_client(ctx) |
| 138 | + |
| 139 | + try: |
| 140 | + results = await list_built_in_datasets( |
| 141 | + client, search=params.search, category=params.category |
| 142 | + ) |
| 143 | + except Exception as e: |
| 144 | + return [TextContent(type="text", text=f"Error browsing built-in lists: {e!r}")] |
| 145 | + |
| 146 | + if not results: |
| 147 | + search_desc = f" matching '{params.search}'" if params.search else "" |
| 148 | + cat_desc = f" in category '{params.category}'" if params.category else "" |
| 149 | + return [ |
| 150 | + TextContent( |
| 151 | + type="text", |
| 152 | + text=f"No built-in lists found{search_desc}{cat_desc}.", |
| 153 | + ) |
| 154 | + ] |
| 155 | + |
| 156 | + lines = [f"Found {len(results)} built-in list(s):\n"] |
| 157 | + for i, item in enumerate(results, 1): |
| 158 | + fields_str = ", ".join(item.fields) if item.fields else "(no fields listed)" |
| 159 | + lines.append( |
| 160 | + f"{i}. {item.name} [{item.category}]\n" |
| 161 | + f" Fields: {fields_str}\n" |
| 162 | + f" artifact_id: {item.artifact_id}\n" |
| 163 | + ) |
| 164 | + lines.append( |
| 165 | + "To use one of these lists, call everyrow_use_list with the artifact_id." |
| 166 | + ) |
| 167 | + |
| 168 | + return [TextContent(type="text", text="\n".join(lines))] |
| 169 | + |
| 170 | + |
| 171 | +@mcp.tool( |
| 172 | + name="everyrow_use_list", |
| 173 | + structured_output=False, |
| 174 | + annotations=ToolAnnotations( |
| 175 | + title="Import Reference List", |
| 176 | + readOnlyHint=False, |
| 177 | + destructiveHint=False, |
| 178 | + idempotentHint=False, |
| 179 | + openWorldHint=False, |
| 180 | + ), |
| 181 | +) |
| 182 | +async def everyrow_use_list( |
| 183 | + params: UseListInput, ctx: EveryRowContext |
| 184 | +) -> list[TextContent]: |
| 185 | + """Import a reference list into your session and save it as a CSV file. |
| 186 | +
|
| 187 | + This copies the dataset into a new session, fetches the data, and saves |
| 188 | + it as a CSV file ready to pass to other everyrow utilities for analysis |
| 189 | + or research. |
| 190 | +
|
| 191 | + The copy is a fast database operation (<1s) — no polling needed. |
| 192 | + """ |
| 193 | + client = _get_client(ctx) |
| 194 | + |
| 195 | + try: |
| 196 | + async with create_session(client=client) as session: |
| 197 | + session_url = session.get_url() |
| 198 | + result = await use_built_in_list( |
| 199 | + artifact_id=UUID(params.artifact_id), |
| 200 | + session=session, |
| 201 | + ) |
| 202 | + |
| 203 | + # Fetch the copied data and save as CSV |
| 204 | + df, _ = await _fetch_task_result(client, str(result.task_id)) |
| 205 | + |
| 206 | + csv_path = Path.cwd() / f"built-in-list-{result.artifact_id}.csv" |
| 207 | + df.to_csv(csv_path, index=False) |
| 208 | + except Exception as e: |
| 209 | + return [TextContent(type="text", text=f"Error importing built-in list: {e!r}")] |
| 210 | + |
| 211 | + return [ |
| 212 | + TextContent( |
| 213 | + type="text", |
| 214 | + text=( |
| 215 | + f"Imported built-in list into your session.\n\n" |
| 216 | + f"CSV saved to: {csv_path}\n" |
| 217 | + f"Rows: {len(df)}\n" |
| 218 | + f"Columns: {', '.join(df.columns)}\n" |
| 219 | + f"Session: {session_url}\n\n" |
| 220 | + f"Pass {csv_path} as input_csv to other everyrow utilities for analysis or research." |
| 221 | + ), |
| 222 | + ) |
| 223 | + ] |
| 224 | + |
| 225 | + |
105 | 226 | @mcp.tool( |
106 | 227 | name="everyrow_agent", |
107 | 228 | structured_output=False, |
|
0 commit comments