@codeflyai/codefly 0.24.0 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -193,8 +193,8 @@ their corresponding top-level category object in your `settings.json` file.
193
193
  - **Default:** `false`
194
194
 
195
195
  - **`ui.hideContextSummary`** (boolean):
196
- - **Description:** Hide the context summary (GEMINI.md, MCP servers) above the
197
- input.
196
+ - **Description:** Hide the context summary (CODEFLY.md, MCP servers) above
197
+ the input.
198
198
  - **Default:** `false`
199
199
 
200
200
  - **`ui.footer.hideCWD`** (boolean):
@@ -567,7 +567,7 @@ their corresponding top-level category object in your `settings.json` file.
567
567
  - **Default:** `[]`
568
568
 
569
569
  - **`context.loadMemoryFromIncludeDirectories`** (boolean):
570
- - **Description:** Controls how /memory refresh loads GEMINI.md files. When
570
+ - **Description:** Controls how /memory refresh loads CODEFLY.md files. When
571
571
  true, include directories are scanned; when false, only the current
572
572
  directory is used.
573
573
  - **Default:** `false`
@@ -0,0 +1,231 @@
1
+ # Database Schema Tool
2
+
3
+ The Database Schema Tool (`get_database_schema`) allows Codefly to retrieve
4
+ database table structures and column information from MySQL or PostgreSQL
5
+ databases. This tool is essential for understanding database schemas, generating
6
+ ORMs, creating migrations, and working with database-driven applications.
7
+
8
+ ## Overview
9
+
10
+ The Database Schema Tool connects to a MySQL or PostgreSQL database and
11
+ retrieves comprehensive schema information including:
12
+
13
+ - Table names
14
+ - Column names and data types
15
+ - Nullable constraints
16
+ - Primary keys and indexes (MySQL)
17
+
18
+ ## How to use
19
+
20
+ ### Basic usage
21
+
22
+ Ask Codefly to fetch database schema information:
23
+
24
+ ```
25
+ > Get the schema for the MySQL database 'myapp_db' on localhost with user 'root'
26
+ ```
27
+
28
+ ```
29
+ > Fetch the PostgreSQL database schema from host db.example.com, database 'production_db', user 'admin'
30
+ ```
31
+
32
+ ### Common use cases
33
+
34
+ #### Understanding database structure
35
+
36
+ ```
37
+ > What tables exist in the MySQL database 'shop_db' on localhost?
38
+ ```
39
+
40
+ #### Generating ORM models
41
+
42
+ ```
43
+ > Get the schema from the PostgreSQL database 'app_db' and generate TypeScript TypeORM entities
44
+ ```
45
+
46
+ #### Creating database documentation
47
+
48
+ ```
49
+ > Fetch the schema from MySQL database 'inventory_db' and create markdown documentation for all tables
50
+ ```
51
+
52
+ #### Database migration planning
53
+
54
+ ```
55
+ > Get the current schema from the dev database and suggest migrations to match the production schema structure
56
+ ```
57
+
58
+ ## Tool parameters
59
+
60
+ The `get_database_schema` tool accepts the following parameters:
61
+
62
+ - **`type`** (required): Database type
63
+ - `mysql`: For MySQL or MariaDB databases
64
+ - `postgres`: For PostgreSQL databases
65
+
66
+ - **`host`** (required): Database host address
67
+ - Examples: `localhost`, `127.0.0.1`, `db.example.com`
68
+
69
+ - **`user`** (required): Username for database connection
70
+
71
+ - **`database`** (required): Name of the database to query
72
+
73
+ - **`password`** (optional): Password for database connection
74
+ - If not provided, will attempt connection without password
75
+
76
+ - **`port`** (optional): Port number
77
+ - Defaults to `3306` for MySQL
78
+ - Defaults to `5432` for PostgreSQL
79
+
80
+ ## Output format
81
+
82
+ The tool returns a formatted list of tables and their columns:
83
+
84
+ ```
85
+ Table: users
86
+ - id (int) [PRI]
87
+ - username (varchar)
88
+ - email (varchar)
89
+ - created_at (timestamp) NULL
90
+
91
+ Table: orders
92
+ - id (int) [PRI]
93
+ - user_id (int) [MUL]
94
+ - total (decimal)
95
+ - status (varchar)
96
+ - created_at (timestamp)
97
+ ```
98
+
99
+ For each column, the output includes:
100
+
101
+ - Column name
102
+ - Data type
103
+ - NULL/NOT NULL constraint
104
+ - Index information (for MySQL: PRI for primary key, MUL for indexed, etc.)
105
+
106
+ ## Dependencies
107
+
108
+ The Database Schema Tool requires database client libraries:
109
+
110
+ ### For MySQL/MariaDB
111
+
112
+ ```bash
113
+ npm install mysql2
114
+ ```
115
+
116
+ ### For PostgreSQL
117
+
118
+ ```bash
119
+ npm install pg
120
+ ```
121
+
122
+ If the required package is not installed, the tool will ask you to install it.
123
+
124
+ ## Security considerations
125
+
126
+ - **Credentials**: Be cautious when providing database passwords. Consider using
127
+ environment variables or secure credential storage
128
+ - **Read-only access**: The tool only reads schema information and does not
129
+ modify data
130
+ - **Network security**: Ensure database connections are made over secure
131
+ networks
132
+ - **Least privilege**: Use database accounts with minimal required permissions
133
+ (e.g., `SHOW TABLES`, `DESCRIBE` for MySQL, or `pg_catalog` read access for
134
+ PostgreSQL)
135
+
136
+ ## Examples
137
+
138
+ ### Example 1: Local development database
139
+
140
+ ```
141
+ > Get the schema from MySQL database 'dev_db' on localhost with user 'root' and no password
142
+ ```
143
+
144
+ ### Example 2: Remote PostgreSQL database
145
+
146
+ ```
147
+ > Connect to PostgreSQL at db.example.com:5432, database 'production_db', user 'readonly', and fetch the complete schema
148
+ ```
149
+
150
+ ### Example 3: Generating TypeORM entities
151
+
152
+ ```
153
+ > Get the schema from MySQL database 'app_db' on localhost and generate TypeORM entities for all tables
154
+ ```
155
+
156
+ Codefly will fetch the schema and generate TypeScript classes with appropriate
157
+ decorators.
158
+
159
+ ### Example 4: Creating database documentation
160
+
161
+ ```
162
+ > Fetch the schema from PostgreSQL database 'analytics_db' and create a comprehensive markdown document describing all tables, their relationships, and fields
163
+ ```
164
+
165
+ ### Example 5: Schema comparison
166
+
167
+ ```
168
+ > Get schemas from both the dev and production databases and show me the differences
169
+ ```
170
+
171
+ ## Troubleshooting
172
+
173
+ ### "The 'mysql2' package is required"
174
+
175
+ For MySQL databases, install the mysql2 package:
176
+
177
+ ```bash
178
+ npm install mysql2
179
+ ```
180
+
181
+ ### "The 'pg' package is required"
182
+
183
+ For PostgreSQL databases, install the pg package:
184
+
185
+ ```bash
186
+ npm install pg
187
+ ```
188
+
189
+ ### "Connection failed"
190
+
191
+ Common connection issues:
192
+
193
+ - **Wrong host/port**: Verify the database server address and port
194
+ - **Authentication failed**: Check username and password
195
+ - **Database doesn't exist**: Ensure the database name is correct
196
+ - **Network issues**: Verify firewall rules and network connectivity
197
+ - **Permissions**: Ensure the user has permission to access schema information
198
+
199
+ ### "Access denied"
200
+
201
+ The database user needs appropriate permissions:
202
+
203
+ For MySQL:
204
+
205
+ ```sql
206
+ GRANT SELECT ON information_schema.* TO 'username'@'host';
207
+ ```
208
+
209
+ For PostgreSQL:
210
+
211
+ ```sql
212
+ GRANT CONNECT ON DATABASE dbname TO username;
213
+ GRANT USAGE ON SCHEMA public TO username;
214
+ ```
215
+
216
+ ## Best practices
217
+
218
+ 1. **Use read-only credentials**: Create database users with minimal required
219
+ permissions
220
+ 2. **Protect passwords**: Avoid hardcoding passwords in prompts; use environment
221
+ variables when possible
222
+ 3. **Test connections**: Verify connectivity with a simple query before running
223
+ complex operations
224
+ 4. **Document schema changes**: Use this tool to track schema evolution over
225
+ time
226
+
227
+ ## See also
228
+
229
+ - [Swagger Schema Tool](./swagger-schema.md) - For retrieving API schemas
230
+ - [File System Tools](./file-system.md) - For working with local schema files
231
+ - [Shell Tool](./shell.md) - For running database migration commands
@@ -86,6 +86,10 @@ Gemini CLI's built-in tools can be broadly categorized as follows:
86
86
  information across sessions.
87
87
  - **[Todo Tool](./todos.md) (`write_todos`):** For managing subtasks of complex
88
88
  requests.
89
+ - **[Database Schema Tool](./database-schema.md) (`get_database_schema`):** For
90
+ retrieving database table structures from MySQL or PostgreSQL databases.
91
+ - **[Swagger Schema Tool](./swagger-schema.md) (`get_swagger_schema`):** For
92
+ fetching and parsing Swagger/OpenAPI schema definitions from URLs.
89
93
 
90
94
  Additionally, these tools incorporate:
91
95
 
@@ -0,0 +1,236 @@
1
+ # Swagger Schema Tool
2
+
3
+ The Swagger Schema Tool (`get_swagger_schema`) allows Codefly to fetch and parse
4
+ Swagger/OpenAPI schema definitions from URLs. This tool is particularly useful
5
+ for understanding API structures, generating API clients, documenting endpoints,
6
+ and integrating with external services.
7
+
8
+ ## Overview
9
+
10
+ The Swagger Schema Tool retrieves Swagger/OpenAPI specifications from a given
11
+ URL and can return them in different formats:
12
+
13
+ - **Summary format** (default): A human-readable overview of the API including
14
+ endpoints, parameters, and models
15
+ - **JSON format**: The complete schema in JSON format
16
+ - **YAML format**: The complete schema in YAML format
17
+
18
+ ## How to use
19
+
20
+ ### Basic usage
21
+
22
+ Simply ask Codefly to fetch a Swagger schema:
23
+
24
+ ```
25
+ > Fetch the Swagger schema from https://api.example.com/swagger.json
26
+ ```
27
+
28
+ ### Specify output format
29
+
30
+ You can request a specific format:
31
+
32
+ ```
33
+ > Get the Swagger schema from https://petstore.swagger.io/v2/swagger.json in JSON format
34
+ ```
35
+
36
+ ```
37
+ > Show me a summary of the API endpoints from https://api.example.com/v2/api-docs
38
+ ```
39
+
40
+ ### Common use cases
41
+
42
+ #### Understanding an API structure
43
+
44
+ ```
45
+ > What endpoints are available in the API at https://api.github.com/swagger.json?
46
+ ```
47
+
48
+ #### Generating API documentation
49
+
50
+ ```
51
+ > Fetch the Swagger schema from https://api.example.com/swagger.json and create a markdown documentation file
52
+ ```
53
+
54
+ #### Comparing API versions
55
+
56
+ ```
57
+ > Compare the endpoints between https://api.example.com/v1/swagger.json and https://api.example.com/v2/swagger.json
58
+ ```
59
+
60
+ #### Creating API clients
61
+
62
+ ```
63
+ > Get the Swagger schema from https://api.example.com/swagger.json and generate a TypeScript client for it
64
+ ```
65
+
66
+ ## Tool parameters
67
+
68
+ The `get_swagger_schema` tool accepts the following parameters:
69
+
70
+ - **`url`** (required): The URL of the Swagger/OpenAPI schema file
71
+ - Examples:
72
+ - `https://api.example.com/swagger.json`
73
+ - `https://api.example.com/v2/api-docs`
74
+ - `https://petstore.swagger.io/v2/swagger.yaml`
75
+
76
+ - **`format`** (optional): The output format
77
+ - `summary` (default): Human-readable overview with endpoints and models
78
+ - `json`: Full schema in JSON format
79
+ - `yaml`: Full schema in YAML format
80
+
81
+ ## Output format
82
+
83
+ ### Summary format
84
+
85
+ The summary format provides:
86
+
87
+ - API title, version, and description
88
+ - OpenAPI/Swagger version
89
+ - Server URLs or base paths
90
+ - List of endpoints with:
91
+ - HTTP method and path
92
+ - Summary and description
93
+ - Operation ID
94
+ - Tags
95
+ - Parameters (name, location, type, required status)
96
+ - Request body information
97
+ - Response codes
98
+ - List of model/schema definitions
99
+
100
+ Example output:
101
+
102
+ ```
103
+ API: Petstore API
104
+ Version: 1.0.0
105
+ Description: This is a sample server Petstore server.
106
+
107
+ OpenAPI/Swagger Version: 3.0.0
108
+ Servers:
109
+ - https://petstore.swagger.io/v2
110
+
111
+ Endpoints:
112
+
113
+ GET /pets
114
+ Summary: List all pets
115
+ Operation ID: listPets
116
+ Tags: pets
117
+ Parameters:
118
+ - limit (query, integer)
119
+ Responses: 200, default
120
+
121
+ POST /pets
122
+ Summary: Create a pet
123
+ Operation ID: createPets
124
+ Tags: pets
125
+ Request Body (required)
126
+ Responses: 201
127
+
128
+ Models/Schemas:
129
+ - Pet
130
+ - Error
131
+ ```
132
+
133
+ ### JSON/YAML formats
134
+
135
+ These formats return the complete Swagger/OpenAPI specification as-is, which is
136
+ useful for:
137
+
138
+ - Importing into API development tools
139
+ - Generating code
140
+ - Detailed schema analysis
141
+ - Integration with other tools
142
+
143
+ ## Supported formats
144
+
145
+ The tool supports both Swagger 2.0 and OpenAPI 3.x specifications in:
146
+
147
+ - JSON format (`.json` files or `application/json` content type)
148
+ - YAML format (`.yaml` or `.yml` files, or `application/x-yaml`/`text/yaml`
149
+ content types)
150
+
151
+ The tool automatically detects the format based on the content type header or
152
+ file extension.
153
+
154
+ ## Dependencies
155
+
156
+ The Swagger Schema Tool uses the following optional dependencies:
157
+
158
+ - **`node-fetch`**: For fetching schemas from URLs (built-in)
159
+ - **`js-yaml`**: For parsing YAML format schemas (optional)
160
+
161
+ If a YAML schema is encountered and `js-yaml` is not installed, the tool will
162
+ ask you to install it:
163
+
164
+ ```bash
165
+ npm install js-yaml
166
+ ```
167
+
168
+ ## Security considerations
169
+
170
+ - The tool fetches schemas from remote URLs, so ensure you trust the source
171
+ - Review the fetched schema before using it to generate code or make API calls
172
+ - The tool does not execute any code from the fetched schema, it only parses and
173
+ displays the structure
174
+
175
+ ## Examples
176
+
177
+ ### Example 1: Exploring a public API
178
+
179
+ ```
180
+ > Fetch the Swagger schema from https://petstore.swagger.io/v2/swagger.json and tell me what endpoints are available
181
+ ```
182
+
183
+ Codefly will fetch the schema, parse it, and provide a summary of all available
184
+ endpoints.
185
+
186
+ ### Example 2: Generating API client code
187
+
188
+ ```
189
+ > Get the Swagger schema from https://api.example.com/v2/api-docs in JSON format, then generate a Python client using the requests library
190
+ ```
191
+
192
+ Codefly will fetch the schema in JSON format and use it to generate a Python
193
+ client.
194
+
195
+ ### Example 3: API documentation
196
+
197
+ ```
198
+ > Fetch the Swagger schema from https://api.example.com/swagger.json and create comprehensive API documentation in markdown format, including all endpoints, parameters, and response schemas
199
+ ```
200
+
201
+ Codefly will analyze the schema and generate human-readable documentation.
202
+
203
+ ## Troubleshooting
204
+
205
+ ### "Failed to fetch Swagger schema: 404 Not Found"
206
+
207
+ The URL you provided does not point to a valid Swagger schema. Common
208
+ Swagger/OpenAPI endpoint paths include:
209
+
210
+ - `/swagger.json`
211
+ - `/swagger.yaml`
212
+ - `/v2/api-docs` (Springfox/SpringDoc)
213
+ - `/openapi.json`
214
+ - `/api-docs`
215
+
216
+ ### "Failed to parse Swagger schema"
217
+
218
+ The content at the URL is not a valid JSON or YAML document. Ensure:
219
+
220
+ - The URL returns a proper Swagger/OpenAPI specification
221
+ - The content type is correct
222
+ - The file is not corrupted
223
+
224
+ ### "The 'js-yaml' package is required"
225
+
226
+ If you're fetching a YAML schema, you need to install js-yaml:
227
+
228
+ ```bash
229
+ npm install js-yaml
230
+ ```
231
+
232
+ ## See also
233
+
234
+ - [Database Schema Tool](./database-schema.md) - For retrieving database schemas
235
+ - [Web Fetch Tool](./web-fetch.md) - For fetching general web content
236
+ - [File System Tools](./file-system.md) - For working with local files
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeflyai/codefly",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
4
4
  "engines": {
5
5
  "node": ">=20.0.0"
6
6
  },
@@ -122,6 +122,8 @@
122
122
  "dependencies": {
123
123
  "ink": "npm:@jrichman/ink@6.4.6",
124
124
  "latest-version": "^9.0.0",
125
+ "mysql2": "^3.16.0",
126
+ "pg": "^8.16.3",
125
127
  "simple-git": "^3.28.0"
126
128
  },
127
129
  "optionalDependencies": {