sap-cap-capire
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSAP CAP-Capire Development Skill
SAP CAP-Capire开发技能
Related Skills
相关技能
- sap-fiori-tools: Use for UI layer development, Fiori Elements integration, and frontend application generation
- sapui5: Use for custom UI development, advanced UI patterns, and freestyle application building
- sap-btp-cloud-platform: Use for deployment options, Cloud Foundry/Kyma configuration, and BTP service integration
- sap-hana-cli: Use for database management, schema inspection, and HDI container administration
- sap-abap: Use for ABAP system integration, external service consumption, and SAP extensions
- sap-btp-best-practices: Use for production deployment patterns and architectural guidance
- sap-ai-core: Use when adding AI capabilities to CAP applications or integrating with SAP AI services
- sap-api-style: Use when documenting CAP OData services or following API documentation standards
- sap-fiori-tools: 用于UI层开发、Fiori Elements集成和前端应用生成
- sapui5: 用于自定义UI开发、高级UI模式和自由风格应用构建
- sap-btp-cloud-platform: 用于部署选项配置、Cloud Foundry/Kyma设置和BTP服务集成
- sap-hana-cli: 用于数据库管理、架构检查和HDI容器管理
- sap-abap: 用于ABAP系统集成、外部服务调用和SAP扩展
- sap-btp-best-practices: 用于生产部署模式和架构指导
- sap-ai-core: 用于为CAP应用添加AI功能或集成SAP AI服务
- sap-api-style: 用于编写CAP OData服务文档或遵循API文档标准
Table of Contents
目录
Quick Start
快速入门
Project Initialization
项目初始化
sh
undefinedsh
undefinedInstall CAP development kit
Install CAP development kit
npm i -g @sap/cds-dk
npm i -g @sap/cds-dk
Create new project
Create new project
cds init <project-name>
cds init <project-name> --add sample,hana
cds init <project-name>
cds init <project-name> --add sample,hana
Start development server with live reload
Start development server with live reload
cds watch
cds watch
Add capabilities
Add capabilities
cds add hana # SAP HANA database
cds add sqlite # SQLite for development
cds add xsuaa # Authentication
cds add mta # Cloud Foundry deployment
cds add multitenancy # SaaS multitenancy
cds add typescript # TypeScript support
undefinedcds add hana # SAP HANA database
cds add sqlite # SQLite for development
cds add xsuaa # Authentication
cds add mta # Cloud Foundry deployment
cds add multitenancy # SaaS multitenancy
cds add typescript # TypeScript support
undefinedBasic Entity Example
基础实体示例
cds
using { cuid, managed } from '@sap/cds/common';
namespace my.bookshop;
entity Books : cuid, managed {
title : String(111) not null;
author : Association to Authors;
stock : Integer;
price : Decimal(9,2);
}
entity Authors : cuid, managed {
name : String(111);
books : Association to many Books on books.author = $self;
}cds
using { cuid, managed } from '@sap/cds/common';
namespace my.bookshop;
entity Books : cuid, managed {
title : String(111) not null;
author : Association to Authors;
stock : Integer;
price : Decimal(9,2);
}
entity Authors : cuid, managed {
name : String(111);
books : Association to many Books on books.author = $self;
}Basic Service
基础服务
cds
using { my.bookshop as my } from '../db/schema';
service CatalogService @(path: '/browse') {
@readonly entity Books as projection on my.Books;
@readonly entity Authors as projection on my.Authors;
@requires: 'authenticated-user'
action submitOrder(book: Books:ID, quantity: Integer) returns String;
}cds
using { my.bookshop as my } from '../db/schema';
service CatalogService @(path: '/browse') {
@readonly entity Books as projection on my.Books;
@readonly entity Authors as projection on my.Authors;
@requires: 'authenticated-user'
action submitOrder(book: Books:ID, quantity: Integer) returns String;
}MCP Integration
MCP集成
This skill integrates with the official CAP MCP (Model Context Protocol) server, providing AI agents with live access to your project's compiled CDS model and CAP documentation.
Available MCP Tools:
- - Fuzzy search for CDS entities, services, actions, and relationships in your compiled CSN model
search_model - - Semantic search through CAP documentation for syntax, patterns, and best practices
search_docs
Key Benefits:
- Instant Model Discovery: Query your project's entities, associations, and services without reading files
- Context-Aware Documentation: Find relevant CAP documentation based on semantic similarity, not keywords
- Zero Configuration: No credentials or environment variables required
- Offline-Capable: All searches are local (model) or cached (docs)
Setup: See MCP Integration Guide for configuration with Claude Code, opencode, or GitHub Copilot.
Use Cases: See MCP Use Cases for real-world examples with quantified ROI (~$131K/developer/year time savings).
Agent Integration: The specialized agents (cap-cds-modeler, cap-service-developer, cap-project-architect, cap-performance-debugger) automatically use these MCP tools as part of their workflows.
本技能与官方CAP MCP(Model Context Protocol)服务器集成,为AI Agent提供对项目已编译CDS模型和CAP文档的实时访问权限。
可用的MCP工具:
- - 在已编译的CSN模型中模糊搜索CDS实体、服务、操作和关系
search_model - - 对CAP文档进行语义搜索,查找语法、模式和最佳实践
search_docs
核心优势:
- 即时模型发现: 无需读取文件即可查询项目的实体、关联和服务
- 上下文感知文档: 基于语义相似度查找相关CAP文档,而非仅依赖关键词
- 零配置: 无需凭证或环境变量
- 离线可用: 所有搜索均为本地(模型)或缓存(文档)查询
设置: 如需配置Claude Code、opencode或GitHub Copilot,请查看MCP集成指南。
使用场景: 请查看MCP使用案例,其中包含可量化投资回报率的实际示例(每位开发者每年约节省13.1万美元时间成本)。
Agent集成: 专用Agent(cap-cds-modeler、cap-service-developer、cap-project-architect、cap-performance-debugger)会在工作流中自动使用这些MCP工具。
Project Structure
项目结构
project/
├── app/ # UI content (Fiori, UI5)
├── srv/ # Service definitions (.cds, .js/.ts)
├── db/ # Data models and schema
│ ├── schema.cds # Entity definitions
│ └── data/ # CSV seed data
├── package.json # Dependencies and CDS config
└── .cdsrc.json # CDS configuration (optional)project/
├── app/ # UI content (Fiori, UI5)
├── srv/ # Service definitions (.cds, .js/.ts)
├── db/ # Data models and schema
│ ├── schema.cds # Entity definitions
│ └── data/ # CSV seed data
├── package.json # Dependencies and CDS config
└── .cdsrc.json # CDS configuration (optional)Core Concepts
核心概念
CDS Built-in Types
CDS内置类型
| CDS Type | SQL Mapping | Common Use |
|---|---|---|
| NVARCHAR(36) | Primary keys |
| NVARCHAR(n) | Text fields |
| INTEGER | Whole numbers |
| DECIMAL(p,s) | Monetary values |
| BOOLEAN | True/false |
| DATE | Calendar dates |
| TIMESTAMP | Date/time |
| CDS类型 | SQL映射 | 常见用途 |
|---|---|---|
| NVARCHAR(36) | 主键 |
| NVARCHAR(n) | 文本字段 |
| INTEGER | 整数 |
| DECIMAL(p,s) | 货币值 |
| BOOLEAN | 布尔值 |
| DATE | 日历日期 |
| TIMESTAMP | 日期时间 |
Common Aspects
通用切面
cds
using { cuid, managed, temporal } from '@sap/cds/common';
// cuid = UUID key
// managed = createdAt, createdBy, modifiedAt, modifiedBy
// temporal = validFrom, validTocds
using { cuid, managed, temporal } from '@sap/cds/common';
// cuid = UUID key
// managed = createdAt, createdBy, modifiedAt, modifiedBy
// temporal = validFrom, validToEvent Handlers (Node.js)
事件处理器(Node.js)
js
// srv/cat-service.js
module.exports = class CatalogService extends cds.ApplicationService {
init() {
const { Books } = this.entities;
// Before handlers - validation
this.before('CREATE', Books, req => {
if (!req.data.title) req.error(400, 'Title required');
});
// On handlers - custom logic
this.on('submitOrder', async req => {
const { book, quantity } = req.data;
// Custom business logic
return { success: true };
});
return super.init();
}
}js
// srv/cat-service.js
module.exports = class CatalogService extends cds.ApplicationService {
init() {
const { Books } = this.entities;
// Before handlers - validation
this.before('CREATE', Books, req => {
if (!req.data.title) req.error(400, 'Title required');
});
// On handlers - custom logic
this.on('submitOrder', async req => {
const { book, quantity } = req.data;
// Custom business logic
return { success: true };
});
return super.init();
}
}Basic CQL Queries
基础CQL查询
js
const { Books } = cds.entities;
// SELECT with conditions
const books = await SELECT.from(Books)
.where({ stock: { '>': 0 } })
.orderBy('title');
// INSERT
await INSERT.into(Books)
.entries({ title: 'New Book', stock: 10 });
// UPDATE
await UPDATE(Books, bookId)
.set({ stock: { '-=': 1 } });js
const { Books } = cds.entities;
// SELECT with conditions
const books = await SELECT.from(Books)
.where({ stock: { '>': 0 } })
.orderBy('title');
// INSERT
await INSERT.into(Books)
.entries({ title: 'New Book', stock: 10 });
// UPDATE
await UPDATE(Books, bookId)
.set({ stock: { '-=': 1 } });Database Setup
数据库设置
Development (SQLite)
开发环境(SQLite)
json
// package.json
{
"cds": {
"requires": {
"db": {
"[development]": {
"kind": "sqlite",
"credentials": { "url": ":memory:" }
},
"[production]": { "kind": "hana" }
}
}
}
}json
// package.json
{
"cds": {
"requires": {
"db": {
"[development]": {
"kind": "sqlite",
"credentials": { "url": ":memory:" }
},
"[production]": { "kind": "hana" }
}
}
}
}Production (SAP HANA)
生产环境(SAP HANA)
sh
cds add hana
cds deploy --to hanash
cds add hana
cds deploy --to hanaInitial Data (CSV)
初始数据(CSV)
- File location:
db/data/my.bookshop-Books.csv - Format:
<namespace>-<EntityName>.csv - Auto-loaded on deployment
- 文件位置:
db/data/my.bookshop-Books.csv - 格式:
<namespace>-<EntityName>.csv - 部署时自动加载
Deployment
部署
Cloud Foundry
Cloud Foundry部署
sh
undefinedsh
undefinedAdd CF deployment support
Add CF deployment support
cds add hana,xsuaa,mta,approuter
cds add hana,xsuaa,mta,approuter
Build and deploy
Build and deploy
npm install --package-lock-only
mbt build
cf deploy mta_archives/<project>_<version>.mtar
undefinednpm install --package-lock-only
mbt build
cf deploy mta_archives/<project>_<version>.mtar
undefinedMultitenancy (SaaS)
多租户(SaaS)
sh
cds add multitenancyConfiguration:
json
{
"cds": {
"requires": {
"multitenancy": true
}
}
}sh
cds add multitenancy配置:
json
{
"cds": {
"requires": {
"multitenancy": true
}
}
}Authorization Examples
授权示例
cds
// Service-level
@requires: 'authenticated-user'
service CatalogService { ... }
// Entity-level
@restrict: [
{ grant: 'READ' },
{ grant: 'WRITE', to: 'admin' }
]
entity Books { ... }cds
// Service-level
@requires: 'authenticated-user'
service CatalogService { ... }
// Entity-level
@restrict: [
{ grant: 'READ' },
{ grant: 'WRITE', to: 'admin' }
]
entity Books { ... }Bundled Resources
捆绑资源
Reference Documentation (22 files)
参考文档(22个文件)
- references/annotations-reference.md - Complete UI annotations reference (10K lines)
- references/cdl-syntax.md - Complete CDL syntax reference (503 lines)
- references/cql-queries.md - CQL query language guide
- references/csn-cqn-cxn.md - Core Schema Notation and query APIs
- references/data-privacy-security.md - GDPR and security implementation
- references/databases.md - Database configuration and deployment
- references/deployment-cf.md - Cloud Foundry deployment details
- references/event-handlers-nodejs.md - Node.js event handler patterns
- references/extensibility-multitenancy.md - SaaS multitenancy implementation
- references/fiori-integration.md - Fiori Elements and UI integration
- references/java-runtime.md - Java runtime support
- references/localization-temporal.md - i18n and temporal data
- references/nodejs-runtime.md - Node.js runtime reference
- references/plugins-reference.md - CAP plugins and extensions
- references/tools-complete.md - Complete CLI tools reference
- references/consuming-services-deployment.md - Service consumption patterns
- references/service-definitions.md - Service definition patterns
- references/event-handlers-patterns.md - Event handling patterns
- references/cql-patterns.md - CQL usage patterns
- references/cli-complete.md - Complete CLI reference
- references/mcp-integration.md - MCP server setup and usage guide (new)
- references/mcp-use-cases.md - Real-world MCP scenarios with quantified ROI (new)
- references/annotations-reference.md - 完整UI注解参考(10000行)
- references/cdl-syntax.md - 完整CDL语法参考(503行)
- references/cql-queries.md - CQL查询语言指南
- references/csn-cqn-cxn.md - 核心模式表示法和查询API
- references/data-privacy-security.md - GDPR和安全实现
- references/databases.md - 数据库配置和部署
- references/deployment-cf.md - Cloud Foundry部署详情
- references/event-handlers-nodejs.md - Node.js事件处理器模式
- references/extensibility-multitenancy.md - SaaS多租户实现
- references/fiori-integration.md - Fiori Elements和UI集成
- references/java-runtime.md - Java运行时支持
- references/localization-temporal.md - 国际化和时态数据
- references/nodejs-runtime.md - Node.js运行时参考
- references/plugins-reference.md - CAP插件和扩展
- references/tools-complete.md - 完整CLI工具参考
- references/consuming-services-deployment.md - 服务调用模式
- references/service-definitions.md - 服务定义模式
- references/event-handlers-patterns.md - 事件处理模式
- references/cql-patterns.md - CQL使用模式
- references/cli-complete.md - 完整CLI参考
- references/mcp-integration.md - MCP服务器设置和使用指南 (新增)
- references/mcp-use-cases.md - 实际MCP场景及量化投资回报率 (新增)
Templates (8 files)
模板(8个文件)
- templates/bookshop-schema.cds - Complete data model example
- templates/catalog-service.cds - Service definition template
- templates/fiori-annotations.cds - UI annotations example
- templates/mta.yaml - Multi-target application descriptor
- templates/package.json - Project configuration template
- templates/service-handler.js - Node.js handler template
- templates/service-handler.ts - TypeScript handler template
- templates/xs-security.json - XSUAA security configuration
- templates/bookshop-schema.cds - 完整数据模型示例
- templates/catalog-service.cds - 服务定义模板
- templates/fiori-annotations.cds - UI注解示例
- templates/mta.yaml - 多目标应用描述符
- templates/package.json - 项目配置模板
- templates/service-handler.js - Node.js处理器模板
- templates/service-handler.ts - TypeScript处理器模板
- templates/xs-security.json - XSUAA安全配置
Quick References
快速参考链接
- CAP Documentation: https://cap.cloud.sap/docs/
- CDS Language: https://cap.cloud.sap/docs/cds/
- Node.js Runtime: https://cap.cloud.sap/docs/node.js/
- Java Runtime: https://cap.cloud.sap/docs/java/
- Best Practices: https://cap.cloud.sap/docs/about/best-practices
- GitHub Repository: https://github.com/cap-js/docs
- CAP文档: https://cap.cloud.sap/docs/
- CDS语言: https://cap.cloud.sap/docs/cds/
- Node.js运行时: https://cap.cloud.sap/docs/node.js/
- Java运行时: https://cap.cloud.sap/docs/java/
- 最佳实践: https://cap.cloud.sap/docs/about/best-practices
- GitHub仓库: https://github.com/cap-js/docs
Common CLI Commands
常用CLI命令
sh
cds init [name] # Create project
cds add <feature> # Add capability
cds watch # Dev server with live reload
cds serve # Start server
cds compile <model> # Compile CDS to CSN/SQL/EDMX
cds deploy --to hana # Deploy to HANA
cds build # Build for deployment
cds env # Show configuration
cds repl # Interactive REPL
cds version # Show version infosh
cds init [name] # Create project
cds add <feature> # Add capability
cds watch # Dev server with live reload
cds serve # Start server
cds compile <model> # Compile CDS to CSN/SQL/EDMX
cds deploy --to hana # Deploy to HANA
cds build # Build for deployment
cds env # Show configuration
cds repl # Interactive REPL
cds version # Show version infoBest Practices
最佳实践
DO ✓
建议做法 ✓
- Use and
cuidaspects frommanaged@sap/cds/common - Keep domain models in , services in
db/, UI insrv/app/ - Use managed associations (let CAP handle foreign keys)
- Design single-purpose services per use case
- Start with SQLite, switch to HANA for production
- 使用中的
@sap/cds/common和cuid切面managed - 将领域模型放在、服务放在
db/、UI放在srv/app/ - 使用托管关联(让CAP处理外键)
- 为每个用例设计单一用途的服务
- 开发阶段使用SQLite,生产阶段切换到HANA
DON'T ✗
不建议做法 ✗
- Don't use SELECT * - be explicit about projections
- Don't bypass CAP's query API with raw SQL
- Don't create microservices prematurely
- Don't hardcode credentials in config files
- Don't write custom OData providers
- 不要使用SELECT * - 明确指定投影字段
- 不要绕过CAP查询API直接使用原生SQL
- 不要过早创建微服务
- 不要在配置文件中硬编码凭证
- 不要编写自定义OData提供程序
Version Information
版本信息
- Skill Version: 2.1.0
- CAP Version: @sap/cds 9.4.x
- MCP Version: @cap-js/mcp-server 0.0.3+
- Last Verified: 2025-12-28
- License: GPL-3.0
- 技能版本: 2.1.0
- CAP版本: @sap/cds 9.4.x
- MCP版本: @cap-js/mcp-server 0.0.3+
- 最后验证日期: 2025-12-28
- 许可证: GPL-3.0