mcpField
E
encore-getting-started

encore-getting-started

github.com/encoredev开发30683 次安装2 天前更新
代码仓库

关于 encore-getting-started

为使用 Encore.ts 的 Agent 提供从检查 CLI、创建并运行应用到连接 MCP 服务的入门流程,并指引后续开发任务对应的技能。

主要功能

  1. 01检查并安装 Encore CLI
  2. 02登录或处理 CI 应用创建
  3. 03创建并验证 Encore.ts 应用
  4. 04配置本地与云端 MCP 服务
  5. 05按开发任务加载后续技能

适用场景

  1. 01首次创建并运行 Encore.ts 应用
  2. 02为编码 Agent 配置 Encore MCP 服务
  3. 03查找添加 API、数据库或测试的后续指引

MCP 相关

指导启动 Encore 本地 MCP 服务,并可在登录后配置 Encore Cloud MCP 服务,让工具检查和调用应用及读取部署信息。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/encoredev/skills --skill encore-getting-started

安装后在 Claude Code 中输入/encore-getting-started确认已加载。

详细介绍

原文在翻译后有更新,译文可能不是最新。

开始使用 Encore.ts

说明

安装 Encore CLI
# macOS
brew install encoredev/tap/encore

# Linux/WSL
curl -L https://encore.dev/install.sh | bash

# Windows (PowerShell)
iwr https://encore.dev/install.ps1 | iex
创建新应用
# Interactive - choose from templates
encore app create my-app

# Or start with a blank app
encore app create my-app --example=ts/hello-world
项目结构

一个最简 Encore.ts 应用:

my-app/
├── encore.app           # App configuration
├── package.json         # Dependencies
├── tsconfig.json        # TypeScript config
├── encore.service.ts    # Service definition
└── api.ts               # API endpoints
encore.app 文件
// encore.app
{
    "id": "my-app"
}

此文件标记 Encore 应用的根目录。id 是应用的唯一标识符。

定义服务

创建 encore.service.ts 来定义服务:

// encore.service.ts
import { Service } from "encore.dev/service";

export default new Service("my-service");
创建第一个 API
// api.ts
import { api } from "encore.dev/api";

interface HelloResponse {
  message: string;
}

export const hello = api(
  { method: "GET", path: "/hello", expose: true },
  async (): Promise<HelloResponse> => {
    return { message: "Hello, World!" };
  }
);
运行应用
# Start the development server
encore run

# Your API is now available at http://localhost:4000
打开本地仪表板
# Opens the local development dashboard
encore run
# Then visit http://localhost:9400

仪表板会显示:

  • 所有服务和端点
  • 请求/响应日志
  • 数据库查询
  • 跟踪和跨度
常用 CLI 命令
命令说明
encore run启动本地开发服务
encore test运行测试
encore db shell <db>打开数据库的 psql shell
encore gen client生成 API 客户端代码
encore app link关联现有的 Encore Cloud 应用
添加数据库
// db.ts
import { SQLDatabase } from "encore.dev/storage/sqldb";

const db = new SQLDatabase("mydb", {
  migrations: "./migrations",
});

创建迁移:

-- migrations/1_create_table.up.sql
CREATE TABLE items (
    id SERIAL PRIMARY KEY,
    name TEXT NOT NULL
);
后续步骤
  • 添加更多端点(参见 encore-api 技能)
  • 添加身份验证(参见 encore-auth 技能)
  • 添加 Pub/Sub 主题(encore-pubsub)、定时任务(encore-cron)、存储桶(encore-bucket)、密钥(encore-secret)或缓存(encore-cache)
  • 部署到 Encore Cloud:先运行 encore app link,然后运行 git push encore

评论

支持 Markdown