Attach a resource to an app
attach_resourceAttach a resource to an app: a named set of environment variables, such as a database's connection string, that the app reads as secrets. Publish the app first, and name the resource. When the organization has none by that name, pass a provider from list_catalog_resources and the first call creates it, returning at once with state provisioning; provisioning takes about a minute. Call again every ten seconds with the same arguments, env_prefix included, until the state is attached: the call that finds the resource ready attaches it, sets its variables, and asks for a restart if the app is running. The state is attaching while Valet still owes the restart or the variables, and conflicted when a name the resource sets is already set on the app; the answer gives the reason. An existing resource attaches by name alone, including one another app holds. One name is one resource, and an app can hold several; pass env_prefix when two would set the same variables. Pass plain_vars for plain configuration the app needs beside the database, name to value; it is readable from the dashboard, and a name or value that looks like a secret is refused. For a secret, such as an API key, pass its name in secret_names and say in reason why it is needed: the call that attaches also returns a request whose url the person opens, signed in to Valet, to enter each value; follow it with get_request, and never ask the person to type a secret into this conversation. plain_vars and secret_names apply only on the call that attaches, so repeat them on every call. A new database is empty, so the app creates its own tables, and its URL carries the TLS settings it needs. The running process sees the variables once the restart completes; get_service shows the attachment's status. Values are never returned here. Credentials in a reason read [redacted]. Requires connecting a Valet account.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"name": "<name>",
"resource": "<resource>"
},
"name": "attach_resource"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The app's name, as list_services shows it: the app to attach the resource to. | |
| plan | No | The provider's plan. Omit to use its first plan. Repeat it on every call for one resource. | |
| reason | No | Shown to the person on the request page to explain why the values are needed, so they can decide whether to enter them, such as: The app charges cards and needs your Stripe key. | |
| org_name | No | The Valet organization the app belongs to. Omit to use the organization the account joined first. | |
| provider | No | The provider to create the resource from, as list_catalog_resources names it. Give it when the organization has no resource by this name. | |
| resource | Yes | Which resource the app gets, such as shop-db. A name the organization holds shares that resource with this app; a new name creates one from provider, which the organization then keeps under that name. A private system is never attached here: the call answers state requested with an access request an org Admin approves within 24 hours. | |
| env_prefix | No | Set the resource's variables under PREFIX_NAME rather than NAME, so two resources that set the same variables can both attach. Omit to use the names as they are. Repeat it on every call for one resource: it applies on the call that attaches. | |
| plain_vars | No | Plain configuration to set in the restart the attach requests, as variable name to value, such as LOG_LEVEL to debug. Readable from the dashboard: never a secret, and a name or value that looks like one is refused. Set on the call that attaches. Leave out the names the resource sets. | |
| secret_names | No | Names of secret variables, such as STRIPE_KEY, for the person to enter on the request page. Never values. Requested on the call that attaches. Leave out the names the resource sets. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| org | Yes | Name of the Valet organization the call acted in. | |
| name | Yes | Name of the app the resource is attached to. | |
| plan | No | Plan the resource runs on. Absent for a resource created from environment variables. | |
| state | Yes | Where the resource or its attachment stands. provisioning: the provider is still creating the resource, so call attach_resource again. attached, attaching, conflicted, detaching, or detached: the state of the attachment to the app, with reason saying why when it is not attached or detached. requested: the resource is a private system, and an org Admin must approve the access request under request; nothing changed yet. failed: provisioning failed, and reason says why. deprovisioning or deprovisioned: the resource is being or has been removed. | |
| reason | No | Why a failed resource failed, as the provider said, or why the attachment is attaching, detaching, or conflicted. Absent when there is nothing to explain. | |
| request | No | The request a person completes in the dashboard to enter a value that must not pass through this conversation. Absent when nothing needs a person. | |
| env_vars | No | Names of the environment variables the attachment sets on the app, or a detach removed from it. Never their values. | |
| provider | No | Provider the resource was provisioned from. Absent for a resource created from environment variables. | |
| resource | Yes | Name of the resource in the organization. Pass it as resource to attach_resource, detach_resource, or destroy_resource. | |
| redactions | Yes | How many credentials were replaced with [redacted] in the text this answer was built from: secret values the service holds, and strings shaped like an API key, a private key, a token, or a password in a URL or header. Redaction is best effort, so 0 does not prove the text holds no credential. | |
| resource_id | No | ID of the resource. Absent when the call stopped before it found or created one. | |
| kept_env_vars | No | Names of variables a detach left on the app because their values are not the ones the resource set. Absent when it kept none. | |
| plain_vars_set | No | Names of the plain_vars this call set on the app, in the restart the attach requested. | |
| plain_vars_not_set | No | Names of the plain_vars this call left unset because it did not attach the resource. Pass them again on the call that attaches. | |
| replaced_resource_id | No | ID of a destroyed resource that held this name before this call provisioned a new one under it. Absent when the call replaced nothing. | |
| secret_names_not_requested | No | Names of the secret_names this call requested no value for because it did not attach the resource. Pass them again on the call that attaches. |