data
PubMed Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the PubMed KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.pubmed.*.
Use lua_read_doc("integrations.pubmed") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
PubMed workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.pubmed.search({}))' --json kosmo integrations:lua --eval 'print(docs.read("pubmed"))' --json
kosmo integrations:lua --eval 'print(docs.read("pubmed.search"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local pubmed = app.integrations.pubmed
local result = pubmed.search({})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.pubmed, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.pubmed.default.* or app.integrations.pubmed.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need PubMed, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
PubMed
Namespace: pubmed
PubMed exposes the public NCBI Entrez E-utilities. This integration defaults to the pubmed database where applicable, but most tools accept db so agents can work with other Entrez databases when the upstream utility supports them.
NCBI allows public use without credentials. For higher request rates and usage compliance, pass api_key, email, and tool on calls. NCBI expects registered email and tool values for production clients.
Search
Use pubmed_search for ESearch. Set usehistory = "y" when you plan to fetch a larger result set through the History server.
local found = pubmed.search({
term = '("large language model"[Title/Abstract]) AND medicine',
retmax = 10,
sort = "pub_date",
usehistory = "y",
})
JSON ESearch responses preserve NCBI fields such as esearchresult.count, esearchresult.idlist, esearchresult.querykey, and esearchresult.webenv.
Summaries And Fetching
Use explicit PubMed IDs:
local summaries = pubmed.summary({
id = { "40654110", "40654099" },
})
Or use History server keys from ESearch or EPost:
local abstracts = pubmed.fetch({
query_key = found.esearchresult.querykey,
WebEnv = found.esearchresult.webenv,
retstart = 0,
retmax = 20,
rettype = "abstract",
retmode = "xml",
})
XML and text responses are returned as:
xmlfor parsed XML trees, with attributes under_attributesand text under_textwhen neededbodyfor plain text responsesstatuscontent_type
Links
Use pubmed_link for ELink. It defaults dbfrom to pubmed.
local links = pubmed.link({
id = "40654110",
db = "pmc",
cmd = "neighbor",
})
Database Info
Use pubmed_info for EInfo metadata, including fields and link names. Omit db to list available Entrez databases.
local info = pubmed.info({
db = "pubmed",
version = "2.0",
})
History Server
Use pubmed_post to save known IDs and pass the returned query_key and WebEnv into summary, fetch, or link tools.
local posted = pubmed.post({
id = { "40654110", "40654099" },
})
Spelling And Global Counts
local spelling = pubmed.spell({
term = "asthmaa",
})
local counts = pubmed.global_query({
term = "CRISPR",
})
pubmed_global_query uses EGQuery and usually returns XML unless NCBI changes the endpoint behavior.
Citation Matching
Use pubmed_citation_match for ECitMatch. Each citation must follow NCBI’s Batch Citation Matcher format:
journal_title|year|volume|first_page|author_name|your_key|
local matches = pubmed.citation_match({
citations = {
"proc natl acad sci u s a|1991|88|3248|mann bj|example-1|",
},
})
Multiple citations are submitted in one request as bdata. The response is generally plain text, so read body for matched PMID rows.
Raw agent markdown
# PubMed
Namespace: `pubmed`
PubMed exposes the public NCBI Entrez E-utilities. This integration defaults to the `pubmed` database where applicable, but most tools accept `db` so agents can work with other Entrez databases when the upstream utility supports them.
NCBI allows public use without credentials. For higher request rates and usage compliance, pass `api_key`, `email`, and `tool` on calls. NCBI expects registered `email` and `tool` values for production clients.
## Search
Use `pubmed_search` for ESearch. Set `usehistory = "y"` when you plan to fetch a larger result set through the History server.
```lua
local found = pubmed.search({
term = '("large language model"[Title/Abstract]) AND medicine',
retmax = 10,
sort = "pub_date",
usehistory = "y",
})
```
JSON ESearch responses preserve NCBI fields such as `esearchresult.count`, `esearchresult.idlist`, `esearchresult.querykey`, and `esearchresult.webenv`.
## Summaries And Fetching
Use explicit PubMed IDs:
```lua
local summaries = pubmed.summary({
id = { "40654110", "40654099" },
})
```
Or use History server keys from ESearch or EPost:
```lua
local abstracts = pubmed.fetch({
query_key = found.esearchresult.querykey,
WebEnv = found.esearchresult.webenv,
retstart = 0,
retmax = 20,
rettype = "abstract",
retmode = "xml",
})
```
XML and text responses are returned as:
- `xml` for parsed XML trees, with attributes under `_attributes` and text under `_text` when needed
- `body` for plain text responses
- `status`
- `content_type`
## Links
Use `pubmed_link` for ELink. It defaults `dbfrom` to `pubmed`.
```lua
local links = pubmed.link({
id = "40654110",
db = "pmc",
cmd = "neighbor",
})
```
## Database Info
Use `pubmed_info` for EInfo metadata, including fields and link names. Omit `db` to list available Entrez databases.
```lua
local info = pubmed.info({
db = "pubmed",
version = "2.0",
})
```
## History Server
Use `pubmed_post` to save known IDs and pass the returned `query_key` and `WebEnv` into summary, fetch, or link tools.
```lua
local posted = pubmed.post({
id = { "40654110", "40654099" },
})
```
## Spelling And Global Counts
```lua
local spelling = pubmed.spell({
term = "asthmaa",
})
local counts = pubmed.global_query({
term = "CRISPR",
})
```
`pubmed_global_query` uses EGQuery and usually returns XML unless NCBI changes the endpoint behavior.
## Citation Matching
Use `pubmed_citation_match` for ECitMatch. Each citation must follow NCBI's Batch Citation Matcher format:
`journal_title|year|volume|first_page|author_name|your_key|`
```lua
local matches = pubmed.citation_match({
citations = {
"proc natl acad sci u s a|1991|88|3248|mann bj|example-1|",
},
})
```
Multiple citations are submitted in one request as `bdata`. The response is generally plain text, so read `body` for matched PMID rows. local result = app.integrations.pubmed.search({})
print(result) Functions
search Read
Search PubMed or another Entrez database with ESearch.
- Lua path
app.integrations.pubmed.search- Full name
pubmed.pubmed_search
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
summary Read
Retrieve document summaries with ESummary.
- Lua path
app.integrations.pubmed.summary- Full name
pubmed.pubmed_summary
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
fetch Read
Fetch full records or abstracts with EFetch.
- Lua path
app.integrations.pubmed.fetch- Full name
pubmed.pubmed_fetch
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
link Read
Retrieve related records and LinkOut URLs with ELink.
- Lua path
app.integrations.pubmed.link- Full name
pubmed.pubmed_link
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
info Read
Inspect Entrez database fields and link names with EInfo.
- Lua path
app.integrations.pubmed.info- Full name
pubmed.pubmed_info
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
post_ids Write
Post IDs to the NCBI History server with EPost.
- Lua path
app.integrations.pubmed.post_ids- Full name
pubmed.pubmed_post
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
spell Read
Get spelling suggestions with ESpell.
- Lua path
app.integrations.pubmed.spell- Full name
pubmed.pubmed_spell
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
global_query Read
Search all Entrez databases and return hit counts with EGQuery.
- Lua path
app.integrations.pubmed.global_query- Full name
pubmed.pubmed_global_query
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
citation_match Read
Match formatted citation strings to PubMed IDs with ECitMatch.
- Lua path
app.integrations.pubmed.citation_match- Full name
pubmed.pubmed_citation_match
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||