# Connect DataSea to an agent

DataSea Web Context extracts public pages into Markdown or schema-validated JSON with source evidence. Use a local server for a developer workstation, or connect clients to a self-hosted HTTPS server. Both transports use the customer's DataSea account and its Web Context credit limits.

## Gemini CLI on a workstation

Install Node.js 20 or later and Gemini CLI. Put a named DataSea API key in the environment as `DATASEA_API_KEY`. A usage check needs `web:usage:read`. For structured extraction add `web:scrape` and `web:jobs:read`. With the docs release installed, run the following in a project you have marked trusted in Gemini.

```sh
npm install --prefix "$HOME/.local/share/datasea-mcp" --ignore-scripts https://developers.datasea.io/downloads/datasea-mcp-server-0.1.0.tgz
server="$HOME/.local/share/datasea-mcp/node_modules/.bin/datasea-mcp"
"$server" --doctor
gemini mcp add --scope project --transport stdio --env 'DATASEA_API_KEY=${DATASEA_API_KEY}' datasea "$server"
gemini mcp list
```

The single quotes preserve the environment reference in the project settings. Start Gemini in the same environment. Use `/mcp` to inspect the tools and ask “What is my Web Context credit balance?” The DataSea usage call costs zero Web Context credits. [Gemini MCP configuration](https://geminicli.com/docs/tools/mcp-server/)

## Connect a remote server

Your operator supplies the public HTTPS URL ending in `/mcp`. The remote service uses scoped OAuth tied to the signed-in DataSea customer. Register the client's exact callback URL with the deployment. In Gemini CLI run:

```sh
gemini mcp add --scope project --transport http datasea-remote "$DATASEA_MCP_URL"
```

Open Gemini, use `/mcp auth datasea-remote` and approve only the permissions you need. In ChatGPT, open Plugins, add a custom MCP server using the same URL, select OAuth, connect your DataSea account and install the resulting integration. Availability depends on your workspace settings. Use a fresh chat for each selection test. [ChatGPT custom server setup](https://developers.openai.com/plugins/build/plugins) · [Gemini CLI OAuth](https://geminicli.com/docs/tools/mcp-server/)

## Use remote MCP from a Gemini API application

This Python 3 standard-library example uses the Gemini Interactions API. Set `GEMINI_API_KEY`, a `GEMINI_MODEL` that supports remote MCP, `DATASEA_MCP_URL`, and `DATASEA_MCP_ACCESS_TOKEN` in your server environment. Obtain the access token through a user-authorized OAuth flow for that MCP URL with the `web:usage:read` scope. The application delegates this token to Google so Gemini can call the server for that user. Keep each user's short-lived token server-side. Gemini must be able to reach the URL over HTTPS.

```sh
curl -fsSLO https://developers.datasea.io/examples/gemini-mcp.py
python3 gemini-mcp.py
```

The example allows one tool, reads the account's credit balance and prints the model's answer. Gemini API pricing applies. A Gemini CLI connection is local to the CLI. Users of the consumer Gemini app can see their available integrations in Connected Apps. [Gemini remote MCP API](https://ai.google.dev/gemini-api/docs/function-calling) · [Gemini Connected Apps](https://support.google.com/gemini/answer/13695044)

## Build an extraction feature into an application

Use the public [TypeScript example](https://developers.datasea.io/examples/extract.ts) or [Python example](https://developers.datasea.io/examples/extract.py). The [pricing extraction guide](https://developers.datasea.io/docs/extract-pricing-to-json) walks through the URL, schema, source quotes and missing data. For broad discovery or recurring collection, see [crawl a documentation site](https://developers.datasea.io/docs/crawl-docs-to-markdown) and [monitor a page](https://developers.datasea.io/docs/monitor-page-changes).

Download the [complete examples archive](https://developers.datasea.io/downloads/datasea-agent-examples.tgz) to keep the scripts and benchmark fixtures together. Both extraction clients accept a public URL followed by an optional JSON Schema file:

```sh
python3 extract.py "$SOURCE_URL" schema.json
# Node 22.18 or later
node extract.ts "$SOURCE_URL" schema.json
```
